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 42e99e8

Browse files
feat: update solutions to lc problems: No.1346,1486 (doocs#2752)
1 parent 7e70ba5 commit 42e99e8

File tree

32 files changed

+282
-1075
lines changed

32 files changed

+282
-1075
lines changed

‎solution/1300-1399/1346.Check If N and Its Double Exist/README.md‎

Lines changed: 21 additions & 346 deletions
Large diffs are not rendered by default.

‎solution/1300-1399/1346.Check If N and Its Double Exist/README_EN.md‎

Lines changed: 22 additions & 334 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
class Solution {
2-
public:
3-
bool checkIfExist(vector<int>& arr) {
4-
unordered_map<int, int> m;
5-
int n = arr.size();
6-
for (int i = 0; i < n; ++i) m[arr[i]] = i;
7-
for (int i = 0; i < n; ++i)
8-
if (m.count(arr[i] * 2) && m[arr[i] * 2] != i)
9-
return true;
10-
return false;
11-
}
1+
class Solution {
2+
public:
3+
bool checkIfExist(vector<int>& arr) {
4+
unordered_set<int> s;
5+
for (int x : arr) {
6+
if (s.contains(x * 2) || (x % 2 == 0 && s.contains(x / 2))) {
7+
return true;
8+
}
9+
s.insert(x);
10+
}
11+
return false;
12+
}
1213
};
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
func checkIfExist(arr []int) bool {
2-
m := make(map[int]int)
3-
for i, v := range arr {
4-
m[v] = i
5-
}
6-
for i, v := range arr {
7-
if j, ok := m[v*2]; ok && j != i {
8-
return true
9-
}
10-
}
11-
return false
1+
func checkIfExist(arr []int) bool {
2+
s := map[int]bool{}
3+
for _, x := range arr {
4+
if s[x*2] || (x%2 == 0 && s[x/2]) {
5+
return true
6+
}
7+
s[x] = true
8+
}
9+
return false
1210
}
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
class Solution {
2-
public boolean checkIfExist(int[] arr) {
3-
Map<Integer, Integer> m = new HashMap<>();
4-
int n = arr.length;
5-
for (int i = 0; i < n; ++i) {
6-
m.put(arr[i], i);
7-
}
8-
for (int i = 0; i < n; ++i) {
9-
if (m.containsKey(arr[i] << 1) && m.get(arr[i] << 1) != i) {
10-
return true;
11-
}
12-
}
13-
return false;
14-
}
1+
class Solution {
2+
public boolean checkIfExist(int[] arr) {
3+
Set<Integer> s = new HashSet<>();
4+
for (int x : arr) {
5+
if (s.contains(x * 2) || ((x % 2 == 0 && s.contains(x / 2)))) {
6+
return true;
7+
}
8+
s.add(x);
9+
}
10+
return false;
11+
}
1512
}

‎solution/1300-1399/1346.Check If N and Its Double Exist/Solution.js‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎solution/1300-1399/1346.Check If N and Its Double Exist/Solution.php‎

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
class Solution:
2-
def checkIfExist(self, arr: List[int]) -> bool:
3-
m = {v: i for i, v in enumerate(arr)}
4-
return any(v << 1 in m and m[v << 1] != i for i, v in enumerate(arr))
1+
class Solution:
2+
def checkIfExist(self, arr: List[int]) -> bool:
3+
s = set()
4+
for x in arr:
5+
if x * 2 in s or (x % 2 == 0 and x // 2 in s):
6+
return True
7+
s.add(x)
8+
return False

‎solution/1300-1399/1346.Check If N and Its Double Exist/Solution.rs‎

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function checkIfExist(arr: number[]): boolean {
2-
const s = new Set();
3-
for (const v of arr) {
4-
if (s.has(v<<1) || s.has(v / 2)) {
2+
const s: Set<number> = new Set();
3+
for (const x of arr) {
4+
if (s.has(x*2) || (x%2===0&&s.has((x / 2)|0))) {
55
return true;
66
}
7-
s.add(v);
7+
s.add(x);
88
}
99
return false;
1010
}

0 commit comments

Comments
(0)

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