Skip to content

Commit 24ffdac

Browse files
committed
add 112, 160, 165, 172, 181, 183, 326, 342, 382, 383, 398, 584, 620, 627, 1137, 1378, 2586, 3024
Also update 70, 118, 168, 171, 468, 509, 535
1 parent b845985 commit 24ffdac

33 files changed

+574
-75
lines changed

0070-climbing-stairs.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
44
Submitted: January 9th, 2025
55
6-
Runtime: 1 ms (beats 3.84%)
7-
Memory: 17.59 MB (beats 37.71%)
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.87 MB (beats 30.40%)
88
"""
99

1010
class Solution:
11-
@functools.lru_cache(maxsize=45)
1211
def climbStairs(self, n: int) -> int:
13-
if n == 0 or n == 1:
14-
return 1
15-
else:
16-
return self.climbStairs(n - 1) + self.climbStairs(n - 2)
12+
a = 0
13+
b = 1
14+
for _ in range(n):
15+
c = a + b
16+
a = b
17+
b = c
18+
return b

0070-climbing-stairs.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
70. Climbing Stairs
3+
4+
Submitted: October 8, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 2.16 MB (beats 45.96%)
8+
*/
9+
10+
impl Solution {
11+
pub fn climb_stairs(n: i32) -> i32 {
12+
let mut a = 0;
13+
let mut b = 1;
14+
for _ in (0..n) {
15+
let c = a + b;
16+
a = b;
17+
b = c;
18+
}
19+
b
20+
}
21+
}

0112-path-sum.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
112. Path Sum
3+
4+
Submitted: June 18, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 19.12 MB (beats 23.39%)
8+
"""
9+
10+
# Definition for a binary tree node.
11+
# class TreeNode:
12+
# def __init__(self, val=0, left=None, right=None):
13+
# self.val = val
14+
# self.left = left
15+
# self.right = right
16+
class Solution:
17+
def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
18+
if not root: return False
19+
if root.left or root.right:
20+
return self.hasPathSum(root.left, targetSum - root.val) or self.hasPathSum(root.right, targetSum - root.val)
21+
return targetSum == root.val

0118-pascals-triangle.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/*
22
118. Pascal's Triangle
33
4-
Submitted: December 10, 2024
4+
Submitted: June 18, 2025
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 9.82 MB (beats 7.86%)
7+
Memory: 9.80 MB (beats 31.17%)
88
*/
99

1010
class Solution {
1111
public:
1212
vector<vector<int>> generate(int numRows) {
13-
vector<vector<int>> res;
14-
res.push_back({1});
13+
vector<vector<int>> res = {vector<int>{1}};
1514
for (int i = 1; i < numRows; ++i) {
16-
vector<int> t;
17-
t.push_back(1);
18-
vector<int>& prev = res.back();
19-
for (int j = 0, n = prev.size(); j < n - 1; ++j) {
20-
t.push_back(prev[j] + prev[j + 1]);
15+
vector<int> t = {1};
16+
for (int j = 0; j < res.back().size() - 1; ++j) {
17+
t.push_back(res.back()[j] + res.back()[j + 1]);
2118
}
2219
t.push_back(1);
2320
res.push_back(t);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
160. Intersection of Two Linked Lists
3+
4+
Submitted: May 31, 2025
5+
6+
Runtime: 40 ms (beats 37.90%)
7+
Memory: 20.66 MB (beats 17.77%)
8+
*/
9+
10+
/**
11+
* Definition for singly-linked list.
12+
* struct ListNode {
13+
* int val;
14+
* ListNode *next;
15+
* ListNode(int x) : val(x), next(NULL) {}
16+
* };
17+
*/
18+
19+
class Solution {
20+
public:
21+
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
22+
if (!headA || !headB) return nullptr;
23+
vector<ListNode*> listA, listB;
24+
for (auto p = headA; p; p = p->next) listA.push_back(p);
25+
for (auto p = headB; p; p = p->next) listB.push_back(p);
26+
if (listA.back() != listB.back()) return nullptr;
27+
if (listB.size() > listA.size()) swap(listA, listB);
28+
for (
29+
auto itA = listA.begin() + (listA.size() - listB.size()), itB = listB.begin();
30+
itA != listA.end(); ++itA, ++itB
31+
) {
32+
if (*itA == *itB) return *itA;
33+
}
34+
throw new runtime_error("Error");
35+
}
36+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
160. Intersection of Two Linked Lists
3+
4+
Submitted: May 31, 2025
5+
6+
Runtime: 84 ms (beats 62.92%)
7+
Memory: 27.87 MB (beats 45.04%)
8+
"""
9+
10+
# Definition for singly-linked list.
11+
# class ListNode:
12+
# def __init__(self, x):
13+
# self.val = x
14+
# self.next = None
15+
16+
def get_nodes(head):
17+
while head:
18+
yield head
19+
head = head.next
20+
21+
class Solution:
22+
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
23+
if not headA or not headB: return None
24+
listA = list(get_nodes(headA))
25+
listB = list(get_nodes(headB))
26+
if listA[-1] is not listB[-1]: return None
27+
if len(listA) < len(listB):
28+
listA, listB = listB, listA
29+
for (a, b) in zip(listA[len(listA) - len(listB):], listB):
30+
if a is b: return a

0165-compare-version-numbers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
165. Compare Version Numbers
3+
4+
Submitted: June 6, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.63 ms (beats 88.97%)
8+
"""
9+
10+
class Solution:
11+
def compareVersion(self, version1: str, version2: str) -> int:
12+
if version1 == version2: return 0
13+
for i,j in itertools.zip_longest(
14+
(int(i) for i in version1.split('.')), (int(i) for i in version2.split('.')),
15+
fillvalue=0
16+
):
17+
if i > j: return 1
18+
if i < j: return -1
19+
return 0

0168-excel-sheet-column-title.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Submitted: October 7, 2024
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 7.19 (beats 96.88%)
7+
Memory: 7.60 MB (beats 90.00%)
88
*/
99

1010
class Solution {
@@ -13,9 +13,10 @@ class Solution {
1313
string col = "";
1414
while (columnNumber > 0) {
1515
columnNumber -= 1;
16-
col.insert(0, 1, (columnNumber % 26) + 65);
16+
col.push_back((columnNumber % 26) + 65);
1717
columnNumber /= 26;
1818
}
19+
reverse(col.begin(), col.end());
1920
return col;
2021
}
21-
};
22+
};

0171-excel-sheet-column-number-alternative.cpp

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

0171-excel-sheet-column-number.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
/*
22
171. Excel Sheet Column Number
33
4-
Submitted: November 27, 2024
4+
Submitted: September 24, 2025
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 8.77 MB (beats 31.86%)
8-
9-
See `0171-excel-sheet-column-number-alternative.cpp` for an alternative solution.
7+
Memory: 8.74 MB (beats 47.20%)
108
*/
119

1210
class Solution {
1311
public:
1412
int titleToNumber(string columnTitle) {
1513
int res = 0;
16-
for ( const char& c : columnTitle ) {
14+
for ( const char c : columnTitle ) {
1715
res *= 26;
18-
res += (int) c - 64; // 'A' == 65
16+
res += (int) c - 64;
1917
}
2018
return res;
2119
}

0 commit comments

Comments
 (0)