Skip to content

Commit f14be0f

Browse files
author
wuduhren
committed
updates
1 parent bcef8a4 commit f14be0f

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Please [BUY ME A COFFEE](https://www.buymeacoffee.com/chriswu) if you want to sh
1313
# Leetcode Problem Lists
1414
I found it makes sense to solve similar problems together, so that we can recognize the problem faster when we encounter a new one. My suggestion is to skip the HARD problems when you first go through these list.
1515

16+
* https://neetcode.io/practice (150 problems with video explaination)
1617
* https://www.programcreek.com/2013/08/leetcode-problem-classification/
1718
* https://github.com/wisdompeak/LeetCode
1819
* https://docs.google.com/spreadsheets/d/1SbpY-04Cz8EWw3A_LBUmDEXKUMO31DBjfeMoA0dlfIA/edit#gid=126913158 ([huahua](https://www.youtube.com/user/xxfflower/videos)).

problems/python3/missing-number.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def missingNumber(self, nums: List[int]) -> int:
3+
N = len(nums)
4+
ans = 0
5+
6+
for n in range(N+1):
7+
ans ^= n
8+
9+
for n in nums:
10+
ans ^= n
11+
12+
return ans

problems/python3/reverse-integer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def reverse(self, x: int) -> int:
3+
MAX = 2**31-1
4+
MIN = -2**31
5+
ans = 0
6+
7+
while x:
8+
digit = int(math.fmod(x, 10))
9+
x = int(x/10)
10+
11+
if ans>MAX//10 or (ans==MAX//10 and digit>MAX%10): return 0
12+
if ans<MIN//10 or (ans==MIN//10 and digit<MIN%10): return 0
13+
14+
ans = ans*10 + digit
15+
16+
return ans
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Does not work with negative values yet.
3+
"""
4+
class Solution:
5+
def getSum(self, a: int, b: int) -> int:
6+
ans = a^b
7+
carry = (a&b)<<1
8+
9+
while carry!=0:
10+
ans, carry = ans^carry, (ans&carry)<<1
11+
12+
return ans

0 commit comments

Comments
 (0)