Skip to content

Commit 8b4d776

Browse files
committed
add 234, 500, 832, 1323, 1678, 1684, 2315, 2725, 3248; update 1, 231, 709, 2011
1 parent 42d9ad3 commit 8b4d776

14 files changed

+247
-18
lines changed

0001-two-sum.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"""
22
1. Two Sum
3-
First solved: February 27, 2024
4-
Last solved: November 22, 2024
3+
4+
Submitted: January 16, 2025
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 17.98 MB (beats 14.36%)
7+
Memory: 19.00 MB (beats 19.63%)
88
"""
99

1010
class Solution:
1111
def twoSum(self, nums: List[int], target: int) -> List[int]:
1212
d = {}
13-
for i in range(len(nums)):
14-
want = target - nums[i]
15-
if want in d:
16-
return [i, d[want]]
17-
else:
18-
d[nums[i]] = i
13+
return next(x for x in (
14+
(i, d[target - nums[i]]) if ((target - nums[i]) in d) else d.update({ nums[i]: i })
15+
for i in range(len(nums))
16+
) if x is not None
17+
)

0231-power-of-two.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/*
22
231. Power of Two
33
4-
Solved: December 9, 2024
4+
Submitted: January 17, 2025
55
66
Runtime: 0 ms (beats 100.00%)
7-
Memory: 7.84 MB (beats 10.33%)
7+
Memory: 7.83 MB (beats 49.22%)
88
*/
99

1010
class Solution {
1111
public:
1212
bool isPowerOfTwo(int n) {
13-
if (n <= 0) return false;
14-
return !(n & (n - 1));
13+
return (n > 0) && !(n & (n - 1));
1514
}
1615
};

0234-palindrome-linked-list.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
234. Palindrome Linked List
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 6 ms (beats 35.32%)
7+
Memory: 132.08 MB (beats 14.40%)
8+
*/
9+
10+
/**
11+
* Definition for singly-linked list.
12+
* struct ListNode {
13+
* int val;
14+
* ListNode *next;
15+
* ListNode() : val(0), next(nullptr) {}
16+
* ListNode(int x) : val(x), next(nullptr) {}
17+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
18+
* };
19+
*/
20+
class Solution {
21+
public:
22+
bool isPalindrome(ListNode* head) {
23+
vector<int> v;
24+
for (; head != nullptr; head = head->next) {
25+
v.push_back(head->val);
26+
}
27+
auto forward = v.cbegin();
28+
auto backward = v.crbegin();
29+
while (forward != v.cend()) {
30+
if (*forward++ != *backward++) return false;
31+
}
32+
return true;
33+
}
34+
};

0500-keyboard-row.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
500. Keyboard Row
3+
4+
Submitted: January 16, 2025
5+
"""
6+
7+
class Solution:
8+
def findWords(self, words: List[str]) -> List[str]:
9+
return [
10+
word for word in words if any(
11+
all(char in row for char in word.lower())
12+
for row in (
13+
'qwertyuiop',
14+
'asdfghjkl',
15+
'zxcvbnm'
16+
)
17+
)
18+
]

0709-to-lower-case.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""
22
709. To Lower Case
33
4-
Submitted: November 22, 2024
4+
Submitted: January 17, 2025
55
66
Runtime: 0 ms (100.00%)
7-
Memory: 16.40 MB (beats 80.46%)
7+
Memory: 17.36 MB (beats 33.60%)
88
"""
99

1010
class Solution:
11-
def __init__(self):
12-
# this is a literal joke
13-
self.toLowerCase = str.lower
11+
def toLowerCase(self, s: str) -> str:
12+
return s.lower()

0832-flipping-an-image.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
832. Flipping an Image
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.73 MB (beats 32.61%)
8+
"""
9+
10+
class Solution:
11+
def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:
12+
return [[int(not k) for k in i] for i in (j[::-1] for j in image)]

1323-maximum-69-number.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
1323. Maximum 69 Number
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.97 MB (beats 15.18%)
8+
"""
9+
10+
class Solution:
11+
def maximum69Number(self, num: int) -> int:
12+
return max(
13+
max(
14+
int(''.join(
15+
('6' if str(num)[i] == '9' else '9') if i == j else str(num)[j] for j in range(len(str(num)))
16+
)) for i in range(len(str(num)))
17+
),
18+
num
19+
)

1678-goal-parser-interpretation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
1678. Goal Parser Interpretation
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 50 ms (beats 33.76%)
7+
Memory: 17.61 MB (beats 35.26%)
8+
"""
9+
10+
class Solution:
11+
def interpret(self, command: str) -> str:
12+
return command.replace('()', 'o').replace('(al)', 'al')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
1684. Count the Number of Consistent Strings
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 258 ms (beats 7.24%)
7+
Memory: 19.71 MB (beats 10.46%)
8+
"""
9+
10+
class Solution:
11+
def countConsistentStrings(self, allowed: str, words: List[str]) -> int:
12+
return sum(all(c in allowed for c in s) for s in words)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
2011. Final Value of Variable After Performing Operations
3+
4+
Submitted: January 17, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 17.88 MB (beats 21.09)
8+
"""
9+
10+
class Solution:
11+
def finalValueAfterOperations(self, operations: List[str]) -> int:
12+
return sum((-1 if op[1] == '-' else 1) for op in operations)

0 commit comments

Comments
 (0)