8000 solved 1346 Β· realtemirov/leetcode@66fc4ee Β· GitHub
[go: up one dir, main page]

Skip to content

Commit 66fc4ee

Browse files
committed
solved 1346
1 parent 8650ba8 commit 66fc4ee

7 files changed

+79
-50
lines changed

β€ŽProblems/1346. Check If N and Its Double Exist.md

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 1346. Check If N and Its Double Exist
2+
3+
🟩 Easy
4+
5+
## Solution
6+
7+
My Solution
8+
9+
```go
10+
func checkIfExist(arr []int) bool {
11+
m := make(map[int]bool, len(arr))
12+
13+
for _, num := range arr {
14+
if _, ok := m[num*2]; ok || (num%2 == 0 && m[num/2]) {
15+
return true
16+
}
17+
m[num] = true
18+
}
19+
20+
return false
21+
}
22+
```
23+
24+
![result](1346.png)
25+
26+
Leetcode: [link](https://leetcode.com/problems/check-if-n-and-its-double-exist/description/)

β€ŽProblems/1346/1346.png

29.1 KB
Loading

β€ŽProblems/1346/solution.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package problem1346
2+
3+
func CheckIfExist(arr []int) bool {
4+
m := make(map[int]bool, len(arr))
5+
6+
for _, num := range arr {
7+
if _, ok := m[num*2]; ok || (num%2 == 0 && m[num/2]) {
8+
return true
9+
}
10+
m[num] = true
11+
}
12+
13+
return false
14+
}

β€ŽProblems/1346/solution_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package problem1346_test
2+
3+
import (
4+
"testing"
5+
6+
problem1346 "github.com/realtemirov/leetcode/Problems/1346"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestSolution(t *testing.T) {
11+
testCases := []struct {
12+
name string
13+
cases []int
14+
expected bool
15+
}{
16+
{
17+
name: "Test 1",
18+
cases: []int{10, 2, 5, 3},
19+
expected: true,
20+
},
21+
{
22+
name: "Test 2",
23+
cases: []int{3, 1, 7, 11},
24+
expected: false,
25+
},
26+
}
27+
28+
for _, tc := range testCases {
29+
t.Run(tc.name, func(t *testing.T) {
30+
result := problem1346.CheckIfExist(tc.cases)
31+
require.Equal(t, tc.expected, result, "expected: %v, result: %v", tc.expected, result)
32+
})
33+
}
34+
}

β€ŽProblems/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Problems
22

3-
> **Total:** `81` \
4-
> **Easy:** `57` \
3+
> **Total:** `82` \
4+
> **Easy:** `58` \
55
> **Medium:** `24` \
66
> **Hard:** `0`
77
@@ -67,6 +67,7 @@
6767
* 🟩 Easy - [1275. Find Winner on a Tic Tac Toe Game](<./1275/1275. Find Winner on a Tic Tac Toe Game.md>)
6868
* 🟩 Easy - [1295. Find Numbers with Even Number of Digits](<./1295/1295. Find Numbers with Even Number of Digits.md>)
6969
* 🟩 Easy - [1342. Number of Steps to Reduce a Number to Zero](<./1342/1342. Number of Steps to Reduce a Number to Zero.md>)
70+
* 🟩 Easy - [1346. Check If N and Its Double Exist](<./1346/1346. Check If N and Its Double Exist.md>)
7071
* 🟩 Easy - [1480. Running Sum of 1d Array](<./1480/1480. Running Sum of 1d Array.md>)
7172
* 🟩 Easy - [1491. Average Salary Excluding the Minimum and Maximum Salary](<./1491/1491. Average Salary Excluding the Minimum and Maximum Salary.md>)
7273
* 🟩 Easy - [1502. Can Make Arithmetic Progression From Sequence](<./1502/1502. Can Make Arithmetic Progression From Sequence.md>)

β€ŽSUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
* [1275. Find Winner on a Tic Tac Toe Game](<./Problems/1275/1275. Find Winner on a Tic Tac Toe Game.md>)
123123
* [1295. Find Numbers with Even Number of Digits](<./Problems/1295/1295. Find Numbers with Even Number of Digits.md>)
124124
* [1342. Number of Steps to Reduce a Number to Zero](<./Problems/1342/1342. Number of Steps to Reduce a Number to Zero.md>)
125+
* [1346. Check If N and Its Double Exist](<./Problems/1346/1346. Check If N and Its Double Exist.md>)
125126
* [1480. Running Sum of 1d Array](<./Problems/1480/1480. Running Sum of 1d Array.md>)
126127
* [1491. Average Salary Excluding the Minimum and Maximum Salary](<./Problems/1491/1491. Average Salary Excluding the Minimum and Maximum Salary.md>)
127128
* [1502. Can Make Arithmetic Progression From Sequence](<./Problems/1502/1502. Can Make Arithmetic Progression From Sequence.md>)
@@ -221,7 +222,7 @@
221222
222223
* [1299. Replace Elements with Greatest Element on Right Side](<Problems/1299. Replace Elements with Greatest Element on Right Side.md>)
223224
224-
* [1346. Check If N and Its Double Exist](<Problems/1346. Check If N and Its Double Exist.md>)
225+
225226
* [1422. Maximum Score After Splitting a String](<Problems/1422. Maximum Score After Splitting a String.md>)
226227
* [1431. Kids With the Greatest Number of Candies](<Problems/1431. Kids With the Greatest Number of Candies.md>)
227228
* [1436. Destination City](<Problems/1436. Destination City.md>)

0 commit comments

Comments
Β (0)
0