Skip to content

Commit 4e47240

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents b2e44a9 + c59a6ba commit 4e47240

File tree

17 files changed

+265
-22
lines changed

17 files changed

+265
-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:

3sum/daiyongg-kim.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution:
2+
def threeSum(self, nums: List[int]) -> List[List[int]]:
3+
nums.sort()
4+
5+
result = []
6+
n = len(nums)
7+
8+
for i in range(n - 2):
9+
10+
if i > 0 and nums[i] == nums[i - 1]:
11+
continue
12+
13+
left = i + 1
14+
right = n - 1
15+
while left < right:
16+
current_sum = nums[i] + nums[left] + nums[right]
17+
18+
if current_sum == 0:
19+
result.append([nums[i], nums[left], nums[right]])
20+
21+
while left < right and nums[left] == nums[left + 1]:
22+
left += 1
23+
24+
while left < right and nums[right] == nums[right - 1]:
25+
right -= 1
26+
27+
left += 1
28+
right -= 1
29+
30+
elif current_sum < 0:
31+
left += 1
32+
33+
else:
34+
right -= 1
35+
36+
return result

climbing-stairs/daiyongg-kim.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def climbStairs(self, n: int) -> int:
3+
if n == 1:
4+
return 1
5+
6+
prev, curr = 1, 2
7+
8+
for i in range(3, n+1):
9+
next = prev + curr
10+
prev = curr
11+
curr = next
12+
13+
return curr
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+
}

linked-list-cycle/DaleSeo.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Definition for singly-linked list.
2+
#[derive(PartialEq, Eq, Clone, Debug)]
3+
pub struct ListNode {
4+
pub val: i32,
5+
pub next: Option<Box<ListNode>>,
6+
}
7+
8+
// TC: O(n)
9+
// SC: O(1)
10+
impl Solution {
11+
pub fn has_cycle(head: Option<Box<ListNode>>) -> bool {
12+
let mut slow = &head;
13+
let mut fast = &head;
14+
15+
while fast.is_some() && fast.as_ref().unwrap().next.is_some() {
16+
slow = &slow.as_ref().unwrap().next;
17+
fast = &fast.as_ref().unwrap().next.as_ref().unwrap().next;
18+
19+
if slow.as_ref().map(|node| node.as_ref() as *const _)
20+
== fast.as_ref().map(|node| node.as_ref() as *const _)
21+
{
22+
return true;
23+
}
24+
}
25+
26+
false
27+
}
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
4+
size = len(nums)
5+
6+
#initialize array as 1
7+
result = [1] * size
8+
9+
left_pass = 1
10+
11+
for i in range(size):A
12+
result[i] *= left_pass
13+
left_pass *= nums[i]
14+
15+
right_pass = 1
16+
for i in range(size-1, -1, -1):
17+
result[i] *= right_pass
18+
right_pass *= nums[i]
19+
20+
return result

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+
}

0 commit comments

Comments
 (0)