Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07a6cca

Browse files
committed
Deploying to main from @ 2xiao/leetcode-js@5995cd3 🚀
1 parent 2eb2b72 commit 07a6cca

26 files changed

+1561
-41
lines changed

‎plan/contest_list.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ headerDepth: 0
204204
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
205205
| :------: | :------ | :------: | :------ | :------: | :------: |
206206
| 3242 | 设计相邻元素求和服务 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/design-neighbor-sum-service) [🔗](https://leetcode.com/problems/design-neighbor-sum-service) |
207-
| 3243 | 新增道路查询后的最短距离 I | | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-i) [🔗](https://leetcode.com/problems/shortest-distance-after-road-addition-queries-i) |
207+
| 3243 | 新增道路查询后的最短距离 I | [[✓]](/problem/3243.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-i) [🔗](https://leetcode.com/problems/shortest-distance-after-road-addition-queries-i) |
208208
| 3244 | 新增道路查询后的最短距离 II | | [`贪心`](/tag/greedy.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-ii) [🔗](https://leetcode.com/problems/shortest-distance-after-road-addition-queries-ii) |
209209
| 3245 | 交替组 III | | [`树状数组`](/tag/binary-indexed-tree.md) [`数组`](/tag/array.md) | 🔴 | [🀄️](https://leetcode.cn/problems/alternating-groups-iii) [🔗](https://leetcode.com/problems/alternating-groups-iii) |
210210

@@ -912,7 +912,7 @@ headerDepth: 0
912912
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
913913
| :------: | :------ | :------: | :------ | :------: | :------: |
914914
| 2923 | 找到冠军 I | | [`数组`](/tag/array.md) [`矩阵`](/tag/matrix.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-champion-i) [🔗](https://leetcode.com/problems/find-champion-i) |
915-
| 2924 | 找到冠军 II | | [`图`](/tag/graph.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-champion-ii) [🔗](https://leetcode.com/problems/find-champion-ii) |
915+
| 2924 | 找到冠军 II | [[✓]](/problem/2924.md) | [`图`](/tag/graph.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-champion-ii) [🔗](https://leetcode.com/problems/find-champion-ii) |
916916
| 2925 | 在树上执行操作以后得到的最大分数 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-score-after-applying-operations-on-a-tree) [🔗](https://leetcode.com/problems/maximum-score-after-applying-operations-on-a-tree) |
917917
| 2926 | 平衡子序列的最大和 | | [`树状数组`](/tag/binary-indexed-tree.md) [`线段树`](/tag/segment-tree.md) [`数组`](/tag/array.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/maximum-balanced-subsequence-sum) [🔗](https://leetcode.com/problems/maximum-balanced-subsequence-sum) |
918918

@@ -1562,7 +1562,7 @@ headerDepth: 0
15621562
| 2574 | 左右元素和的差值 | | [`数组`](/tag/array.md) [`前缀和`](/tag/prefix-sum.md) | 🟢 | [🀄️](https://leetcode.cn/problems/left-and-right-sum-differences) [🔗](https://leetcode.com/problems/left-and-right-sum-differences) |
15631563
| 2575 | 找出字符串的可整除数组 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-divisibility-array-of-a-string) [🔗](https://leetcode.com/problems/find-the-divisibility-array-of-a-string) |
15641564
| 2576 | 求出最多标记下标 | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/find-the-maximum-number-of-marked-indices) [🔗](https://leetcode.com/problems/find-the-maximum-number-of-marked-indices) |
1565-
| 2577 | 在网格图中访问一个格子的最少时间 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-time-to-visit-a-cell-in-a-grid) [🔗](https://leetcode.com/problems/minimum-time-to-visit-a-cell-in-a-grid) |
1565+
| 2577 | 在网格图中访问一个格子的最少时间 | [[✓]](/problem/2577.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-time-to-visit-a-cell-in-a-grid) [🔗](https://leetcode.com/problems/minimum-time-to-visit-a-cell-in-a-grid) |
15661566

15671567

15681568
## Weekly Contest 333 (2023年02月19日 10:30)
@@ -2258,7 +2258,7 @@ headerDepth: 0
22582258
| 2287 | 重排字符形成目标字符串 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/rearrange-characters-to-make-target-string) [🔗](https://leetcode.com/problems/rearrange-characters-to-make-target-string) |
22592259
| 2288 | 价格减免 | | [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/apply-discount-to-prices) [🔗](https://leetcode.com/problems/apply-discount-to-prices) |
22602260
| 2289 | 使数组按非递减顺序排列 | | [`栈`](/tag/stack.md) [`数组`](/tag/array.md) [`链表`](/tag/linked-list.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/steps-to-make-array-non-decreasing) [🔗](https://leetcode.com/problems/steps-to-make-array-non-decreasing) |
2261-
| 2290 | 到达角落需要移除障碍物的最小数目 | | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-obstacle-removal-to-reach-corner) [🔗](https://leetcode.com/problems/minimum-obstacle-removal-to-reach-corner) |
2261+
| 2290 | 到达角落需要移除障碍物的最小数目 | [[✓]](/problem/2290.md) | [`广度优先搜索`](/tag/breadth-first-search.md) [`图`](/tag/graph.md) [`数组`](/tag/array.md) `3+` | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-obstacle-removal-to-reach-corner) [🔗](https://leetcode.com/problems/minimum-obstacle-removal-to-reach-corner) |
22622262

22632263

22642264
## Biweekly Contest 79 (2022年05月28日 22:30)
@@ -2676,7 +2676,7 @@ headerDepth: 0
26762676
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
26772677
| :------: | :------ | :------: | :------ | :------: | :------: |
26782678
| 2108 | 找出数组中的第一个回文字符串 | | [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) | 🟢 | [🀄️](https://leetcode.cn/problems/find-first-palindromic-string-in-the-array) [🔗](https://leetcode.com/problems/find-first-palindromic-string-in-the-array) |
2679-
| 2109 | 向字符串添加空格 | | [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/adding-spaces-to-a-string) [🔗](https://leetcode.com/problems/adding-spaces-to-a-string) |
2679+
| 2109 | 向字符串添加空格 | [[✓]](/problem/2109.md) | [`数组`](/tag/array.md) [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/adding-spaces-to-a-string) [🔗](https://leetcode.com/problems/adding-spaces-to-a-string) |
26802680
| 2110 | 股票平滑下跌阶段的数目 | | [`数组`](/tag/array.md) [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-smooth-descent-periods-of-a-stock) [🔗](https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock) |
26812681
| 2111 | 使数组 K 递增的最少操作次数 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) | 🔴 | [🀄️](https://leetcode.cn/problems/minimum-operations-to-make-the-array-k-increasing) [🔗](https://leetcode.com/problems/minimum-operations-to-make-the-array-k-increasing) |
26822682

@@ -2714,7 +2714,7 @@ headerDepth: 0
27142714
| 2094 | 找出 3 位偶数 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`枚举`](/tag/enumeration.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/finding-3-digit-even-numbers) [🔗](https://leetcode.com/problems/finding-3-digit-even-numbers) |
27152715
| 2095 | 删除链表的中间节点 | [[✓]](/problem/2095.md) | [`链表`](/tag/linked-list.md) [`双指针`](/tag/two-pointers.md) | 🟠 | [🀄️](https://leetcode.cn/problems/delete-the-middle-node-of-a-linked-list) [🔗](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list) |
27162716
| 2096 | 从二叉树一个节点到另一个节点每一步的方向 | | [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) [`字符串`](/tag/string.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/step-by-step-directions-from-a-binary-tree-node-to-another) [🔗](https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another) |
2717-
| 2097 | 合法重新排列数对 | | [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) [`欧拉回路`](/tag/eulerian-circuit.md) | 🔴 | [🀄️](https://leetcode.cn/problems/valid-arrangement-of-pairs) [🔗](https://leetcode.com/problems/valid-arrangement-of-pairs) |
2717+
| 2097 | 合法重新排列数对 | [[✓]](/problem/2097.md) | [`深度优先搜索`](/tag/depth-first-search.md) [`图`](/tag/graph.md) [`欧拉回路`](/tag/eulerian-circuit.md) | 🔴 | [🀄️](https://leetcode.cn/problems/valid-arrangement-of-pairs) [🔗](https://leetcode.com/problems/valid-arrangement-of-pairs) |
27182718

27192719

27202720
## Weekly Contest 269 (2021年11月28日 10:30)
@@ -4151,7 +4151,7 @@ headerDepth: 0
41514151
<!-- prettier-ignore -->
41524152
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
41534153
| :------: | :------ | :------: | :------ | :------: | :------: |
4154-
| 1455 | 检查单词是否为句中其他单词的前缀 | | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) [`字符串匹配`](/tag/string-matching.md) | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) [🔗](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) |
4154+
| 1455 | 检查单词是否为句中其他单词的前缀 | [[✓]](/problem/1455.md) | [`双指针`](/tag/two-pointers.md) [`字符串`](/tag/string.md) [`字符串匹配`](/tag/string-matching.md) | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) [🔗](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) |
41554155
| 1456 | 定长子串中元音的最大数目 | [[✓]](/problem/1456.md) | [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-number-of-vowels-in-a-substring-of-given-length) [🔗](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) |
41564156
| 1457 | 二叉树中的伪回文路径 | | [`位运算`](/tag/bit-manipulation.md) [`树`](/tag/tree.md) [`深度优先搜索`](/tag/depth-first-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/pseudo-palindromic-paths-in-a-binary-tree) [🔗](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree) |
41574157
| 1458 | 两个子序列的最大点积 | | [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) | 🔴 | [🀄️](https://leetcode.cn/problems/max-dot-product-of-two-subsequences) [🔗](https://leetcode.com/problems/max-dot-product-of-two-subsequences) |
@@ -4415,7 +4415,7 @@ headerDepth: 0
44154415
<!-- prettier-ignore -->
44164416
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
44174417
| :------: | :------ | :------: | :------ | :------: | :------: |
4418-
| 1346 | 检查整数及其两倍数是否存在 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-n-and-its-double-exist) [🔗](https://leetcode.com/problems/check-if-n-and-its-double-exist) |
4418+
| 1346 | 检查整数及其两倍数是否存在 | [[✓]](/problem/1346.md) | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) `2+` | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-n-and-its-double-exist) [🔗](https://leetcode.com/problems/check-if-n-and-its-double-exist) |
44194419
| 1347 | 制造字母异位词的最小步骤数 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-number-of-steps-to-make-two-strings-anagram) [🔗](https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram) |
44204420
| 1348 | 推文计数 | | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`二分查找`](/tag/binary-search.md) `2+` | 🟠 | [🀄️](https://leetcode.cn/problems/tweet-counts-per-frequency) [🔗](https://leetcode.com/problems/tweet-counts-per-frequency) |
44214421
| 1349 | 参加考试的最大学生数 | | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`动态规划`](/tag/dynamic-programming.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/maximum-students-taking-exam) [🔗](https://leetcode.com/problems/maximum-students-taking-exam) |

‎problem/0460.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,4 @@ class DLinkedList {
358358
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
359359
| :------: | :------ | :------: | :------ | :------: | :------: |
360360
| 146 | LRU 缓存 | [[]](/problem/0146.md) | [`设计`](/tag/design.md) [`哈希表`](/tag/hash-table.md) [`链表`](/tag/linked-list.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/lru-cache) [🔗](https://leetcode.com/problems/lru-cache) |
361-
| 588 | 设计内存文件系统 🔒 | | [`设计`](/tag/design.md) [`字典树`](/tag/trie.md) [`哈希表`](/tag/hash-table.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/design-in-memory-file-system) [🔗](https://leetcode.com/problems/design-in-memory-file-system) |
361+
| 588 | 设计内存文件系统 🔒 | | [`设计`](/tag/design.md) [`字典树`](/tag/trie.md) [`哈希表`](/tag/hash-table.md) `2+` | 🔴 | [🀄️](https://leetcode.cn/problems/design-in-memory-file-system) [🔗](https://leetcode.com/problems/design-in-memory-file-system) |

‎problem/1346.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: 1346. 检查整数及其两倍数是否存在
3+
description: LeetCode 1346. 检查整数及其两倍数是否存在题解,Check If N and Its Double Exist,包含解题思路、复杂度分析以及完整的 JavaScript 代码实现。
4+
keywords:
5+
- LeetCode
6+
- 1346. 检查整数及其两倍数是否存在
7+
- 检查整数及其两倍数是否存在
8+
- Check If N and Its Double Exist
9+
- 解题思路
10+
- 数组
11+
- 哈希表
12+
- 双指针
13+
- 二分查找
14+
- 排序
15+
---
16+
17+
# 1346. 检查整数及其两倍数是否存在
18+
19+
🟢 <font color=#15bd66>Easy</font>&emsp; 🔖&ensp; [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`双指针`](/tag/two-pointers.md) [`二分查找`](/tag/binary-search.md) [`排序`](/tag/sorting.md)&emsp; 🔗&ensp;[`力扣`](https://leetcode.cn/problems/check-if-n-and-its-double-exist) [`LeetCode`](https://leetcode.com/problems/check-if-n-and-its-double-exist)
20+
21+
## 题目
22+
23+
Given an array `arr` of integers, check if there exist two indices `i` and `j`
24+
such that :
25+
26+
- `i != j`
27+
- `0 <= i, j < arr.length`
28+
- `arr[i] == 2 * arr[j]`
29+
30+
**Example 1:**
31+
32+
> Input: arr = [10,2,5,3]
33+
>
34+
> Output: true
35+
>
36+
> Explanation: For i = 0 and j = 2, arr[i] == 10 == 2 _ 5 == 2 _ arr[j]
37+
38+
**Example 2:**
39+
40+
> Input: arr = [3,1,7,11]
41+
>
42+
> Output: false
43+
>
44+
> Explanation: There is no i and j that satisfy the conditions.
45+
46+
**Constraints:**
47+
48+
- `2 <= arr.length <= 500`
49+
- `-10^3 <= arr[i] <= 10^3`
50+
51+
## 题目大意
52+
53+
给你一个整数数组 `arr`,请你检查是否存在两个整数 `N``M`,满足 `N``M` 的两倍(即,`N = 2 * M`)。
54+
55+
更正式地,检查是否存在两个下标 `i``j` 满足:
56+
57+
- `i != j`
58+
- `0 <= i, j < arr.length`
59+
- `arr[i] == 2 * arr[j]`
60+
61+
**示例 1:**
62+
63+
> **输入:** arr = [10,2,5,3]
64+
>
65+
> **输出:** true
66+
>
67+
> **解释:** N = 10 是 M = 5 的两倍,即 10 = 2 \* 5 。
68+
69+
**示例 2:**
70+
71+
> **输入:** arr = [7,1,14,11]
72+
>
73+
> **输出:** true
74+
>
75+
> **解释:** N = 14 是 M = 7 的两倍,即 14 = 2 \* 7 。
76+
77+
**示例 3:**
78+
79+
> **输入:** arr = [3,1,7,11]
80+
>
81+
> **输出:** false
82+
>
83+
> **解释:** 在该情况下不存在 N 和 M 满足 N = 2 \* M 。
84+
85+
**提示:**
86+
87+
- `2 <= arr.length <= 500`
88+
- `-10^3 <= arr[i] <= 10^3`
89+
90+
## 解题思路
91+
92+
这道题可以使用哈希集合 (Set) 解决。
93+
94+
- 遍历数组中的每个数字 `num`
95+
- 对于每个 `num`,检查以下两种情况:
96+
- 是否存在 `2 * num` 在集合中(即 `num` 的两倍已出现)。
97+
- 是否存在 `num / 2` 在集合中(即 `num` 是某个数的两倍)。
98+
- 如果满足上述任意条件,则返回 `true`
99+
- 否则,将当前数字添加到集合中。
100+
101+
#### 复杂度分析
102+
103+
- **时间复杂度**:`O(n)`,其中 `n` 是数组长度,需要遍历数组中的每个元素一次,每次查找和插入集合的复杂度为 `O(1)`,总时间复杂度为 `O(n)`,
104+
- **空间复杂度**:`O(n)`,使用一个集合来存储最多 `n` 个元素。
105+
106+
## 代码
107+
108+
```javascript
109+
/**
110+
* @param {number[]} arr
111+
* @return {boolean}
112+
*/
113+
var checkIfExist = function (arr) {
114+
let set = new Set();
115+
for (let num of arr) {
116+
// 检查 set 中是否存在 2 * num or num / 2
117+
if (set.has(2 * num) || set.has(num / 2)) {
118+
return true;
119+
}
120+
// 将当前数字加入 set 中
121+
set.add(num);
122+
}
123+
// 没找到两倍数
124+
return false;
125+
};
126+
```
127+
128+
## 相关题目
129+
130+
<!-- prettier-ignore -->
131+
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
132+
| :------: | :------ | :------: | :------ | :------: | :------: |
133+
| 2154 | 将找到的值乘以 2 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`排序`](/tag/sorting.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/keep-multiplying-found-values-by-two) [🔗](https://leetcode.com/problems/keep-multiplying-found-values-by-two) |

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /