Skip to content

Commit 2d0af49

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 2c28ffe + d9dd2d8 commit 2d0af49

File tree

11 files changed

+106
-22
lines changed

11 files changed

+106
-22
lines changed

.github/workflows/integration.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ name: Integration 🔄
22

33
on:
44
pull_request:
5-
merge_group:
65

76
jobs:
87
linelint:
98
runs-on: ubuntu-latest
10-
if: github.event_name == 'pull_request'
119
steps:
1210
- uses: actions/checkout@v4
1311
with:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def containsDuplicate(self, nums: List[int]) -> bool:
3+
s = set()
4+
for num in nums:
5+
if num in s:
6+
return True
7+
s.add(num)
8+
return False

contains-duplicate/devyejin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
class Solution(object):
2-
def containsDuplicate(self, nums):
3-
return len(nums) != len(set(nums))
1+
from typing import List
2+
"""
3+
time complexity : O(n)
4+
space complexity : O(n)
5+
"""
6+
class Solution:
7+
def containsDuplicate(self, nums: List[int]) -> bool:
8+
return len(set(nums)) == len(nums)
49

contains-duplicate/ljh981009.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function containsDuplicate(nums: number[]): boolean {
2+
const result = new Set(nums);
3+
return result.size !== nums.length;
4+
}

contains-duplicate/pastelto.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Return true when array contains duplicated number
3+
*/
4+
class Solution {
5+
public boolean containsDuplicate(int[] nums) {
6+
HashSet<Integer> set = new HashSet<>();
7+
8+
for (int num : nums) {
9+
if (set.contains(num)) return true;
10+
set.add(num);
11+
}
12+
return false;
13+
}
14+
}

reverse-bits/DaleSeo.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// TC: O(1)
2+
// SC: O(1)
3+
impl Solution {
4+
pub fn reverse_bits(n: i32) -> i32 {
5+
let mut result = 0u32;
6+
let mut num = n as u32;
7+
8+
for i in 0..32 {
9+
// Extract the least significant bit
10+
let bit = num & 1;
11+
// Place it in the reversed position
12+
result |= bit << (31 - i);
13+
// Shift num right to process the next bit
14+
num >>= 1;
15+
}
16+
17+
result as i32
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3+
counter = dict()
4+
5+
for num in nums:
6+
if num in counter:
7+
counter[num] += 1
8+
else:
9+
counter[num] = 1
10+
11+
return [num[0] for num in sorted(counter.items(), key=lambda x: x[1])[-k:]]
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
"""
2+
time complexity: O(nlogn)
3+
space complexity: O(n)
4+
"""
5+
6+
from typing import List
17
from collections import Counter
2-
import heapq
8+
from heapq import nlargest
9+
10+
class Solution:
11+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
12+
count = Counter(nums)
13+
return [num for num, _ in nlargest(k, count.items(), key=lambda x: x[1])]
314

415

5-
class Solution(object):
6-
def topKFrequent(self, nums, k):
7-
counter = sorted(Counter(nums).items(), key=lambda item: -item[1])
8-
return list(num for num, count in counter[:k])
916

two-sum/deepInTheWoodz.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
passed = dict()
4+
5+
for i, num in enumerate(nums):
6+
other = target - num
7+
if other in passed:
8+
return [passed[other], i]
9+
passed[num] = i

two-sum/devyejin.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
class Solution(object):
2-
def twoSum(self, nums, target):
1+
from typing import List
32

4-
nums_tuple = sorted(list(enumerate(nums)), key=lambda x: x[1])
5-
left, right = 0, len(nums) - 1
63

7-
while left < right:
8-
temp_sum = nums_tuple[left][1] + nums_tuple[right][1]
9-
if temp_sum == target:
10-
return [nums_tuple[left][0], nums_tuple[right][0]]
11-
elif temp_sum < target:
12-
left += 1
13-
else:
14-
right -= 1
4+
class Solution:
5+
def twoSum(self, nums: List[int], target: int) -> List[int]:
6+
seen = {}
7+
for idx, num in enumerate(nums):
8+
need = target - num
9+
if need in seen:
10+
return [idx, seen[need]]
11+
seen[num] = idx
1512

0 commit comments

Comments
 (0)