Skip to content

Commit 7689c75

Browse files
Chris WuChris Wu
Chris Wu
authored and
Chris Wu
committed
readme
1 parent b665542 commit 7689c75

22 files changed

+38
-139
lines changed

3sum.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ class Solution(object):
22
#this is the answer from caikehe and all the comments below
33

44
"""
5-
the main idea is to iterate every number in nums.
6-
we use the number as a target to find two other numbers which make total zero.
7-
for those two other numbers, we move pointers, l and r, to try them.
5+
This is the answer from caikehe and all the comments below
6+
7+
The main idea is to iterate every number in nums.
8+
We use the number as a target to find two other numbers which make total zero.
9+
For those two other numbers, we move pointers, l and r, to try them.
810
911
l start from left to right
1012
r start from right to left
11-
12-
first, we sort the array, so we can easily move i around and know how to adjust l and r.
13-
if the number is the same as the number before, we have used it as target already, continue. [1]
14-
we always start the left pointer from i+1 because the combination has already tried. [2]
1513
16-
now we calculate the total
17-
if the total is less than zero, we need it to be larger, so we move the left pointer. [3]
18-
if the total is greater than zero, we need it to be smaller, so we move the right pointer. [4]
19-
if the total is zero, bingo! [5]
20-
we need to move the left and right pointers to the next different numbers, so we do not get repeating result. [6]
14+
First, we sort the array, so we can easily move i around and know how to adjust l and r.
15+
If the number is the same as the number before, we have used it as target already, continue. [1]
16+
We always start the left pointer from i+1 because the combination of 0~i has already been tried. [2]
17+
18+
Now we calculate the total:
19+
If the total is less than zero, we need it to be larger, so we move the left pointer. [3]
20+
If the total is greater than zero, we need it to be smaller, so we move the right pointer. [4]
21+
If the total is zero, bingo! [5]
22+
We need to move the left and right pointers to the next different numbers, so we do not get repeating result. [6]
2123
22-
we do not need to consider i after nums[i]>0, since sum of positive will be always greater than zero. [7]
23-
we do not need to try the last two, since there are no rooms for l and r pointers.
24+
We do not need to consider i after nums[i]>0, since sum of 3 positive will be always greater than zero. [7]
25+
We do not need to try the last two, since there are no rooms for l and r pointers.
2426
You can think of it as The last two have been tried by all others. [8]
2527
"""
2628

@@ -50,12 +52,6 @@ def threeSum(self, nums):
5052
r-=1
5153
return res
5254

53-
"""
54-
I really take time to make the best solution, because I wanted to help people understand.
55-
If you like my answer, a star on GitHub I will really appreciated.
56-
https://github.com/wuduhren/leetcode-
57-
"""
58-
5955
"""
6056
def threeSum(self, nums):
6157
def twoSum(target, nums):

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Leetcode Python Solution
2+
1. This is my Python Solution on leetcode `@christopherwu0529`.
3+
4+
2. The question is at `<https://leetcode.com/problems/the-file-name/>`.
5+
6+
For example, `merge-sorted-array.py`'s question is at <https://leetcode.com/problems/merge-sorted-array/>.
7+
8+
9+
3. I really take time tried to make the best solution or explaination, because I wanted to help others like me. If you like my answer, a star on GitHub means a lot to me. <https://github.com/wuduhren/leetcode-python>.

add-binary.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#https://leetcode.com/problems/add-binary/
22
class Solution(object):
33
def addBinary(self, a, b):
4-
return bin(int(a, 2)+int(b, 2))[2:]
5-
6-
"""
7-
I really take time to make the best solution, because I wanted to help people understand.
8-
If you like my answer, a star on GitHub I will really appreciated.
9-
https://github.com/wuduhren/leetcode-python
10-
"""
4+
return bin(int(a, 2)+int(b, 2))[2:]

best-time-to-buy-an-stock.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ def maxProfit(self, prices):
1111
minPrice = price
1212
if (price-minPrice>maxProfit):
1313
maxProfit = price-minPrice
14-
return maxProfit
15-
16-
"""
17-
I really take time to make the best solution, because I wanted to help people understand.
18-
If you like my answer, a star on GitHub I will really appreciated.
19-
https://github.com/wuduhren/leetcode-python
20-
"""
14+
return maxProfit

binary-search-tree-iterator.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,4 @@ def hasNext(self):
3333
# Your BSTIterator object will be instantiated and called as such:
3434
# obj = BSTIterator(root)
3535
# param_1 = obj.next()
36-
# param_2 = obj.hasNext()
37-
38-
"""
39-
I really take time to make the best solution, because I wanted to help people understand.
40-
If you like my answer, a star on GitHub I will really appreciated.
41-
https://github.com/wuduhren/leetcode-python
42-
"""
36+
# param_2 = obj.hasNext()

first-unique-character-in-a-string.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ def firstUniqChar(self, string):
1414
if counter[char]==1:
1515
return i
1616

17-
return -1
18-
19-
"""
20-
I really take time to make the best solution, because I wanted to help people understand.
21-
If you like my answer, a star on GitHub I will really appreciated.
22-
https://github.com/wuduhren/leetcode-python
23-
"""
17+
return -1

group-anagrams.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,4 @@ def groupAnagrams(self, strs):
1111

1212
dic[tuple(string_count)].append(string)
1313

14-
return dic.values()
15-
16-
"""
17-
I really take time to make the best solution, because I wanted to help people understand.
18-
If you like my answer, a star on GitHub I will really appreciated.
19-
https://github.com/wuduhren/leetcode-
20-
"""
14+
return dic.values()

linked-list-cycle.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,4 @@ def hasCycle(self, head):
88
slow = slow.next
99
if (fast==slow):
1010
return True
11-
return False
12-
13-
"""
14-
I really take time to make the best solution, because I wanted to help people understand.
15-
If you like my answer, a star on GitHub I will really appreciated.
16-
https://github.com/wuduhren/leetcode-python
17-
"""
11+
return False

longest-common-prefix.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,4 @@ def longestCommonPrefix(self, strs):
1414
return ''
1515
else:
1616
return bench_mark[:i-1]
17-
return bench_mark
18-
19-
"""
20-
I really take time to make the best solution, because I wanted to help people understand.
21-
If you like my answer, a star on GitHub I will really appreciated.
22-
https://github.com/wuduhren/leetcode-python
23-
"""
17+
return bench_mark

longest-palindromic-substring.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,4 @@ def findPalindorome(mid, mid2=None):
4141
max_pal = p2 if len(p2)>len(max_pal) else max_pal
4242

4343
return max_pal
44-
"""
45-
I really take time to explain my solution, because I wanted to help people understand.
46-
If you like my answer, a star on GitHub I will really appreciated.
47-
https://github.com/wuduhren/leetcode-python
48-
"""
4944

longest-substring-without-repeating-characters.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,4 @@ def lengthOfLongestSubstring(self, s):
3232
counter = max(counter, i-start+1)
3333
mark[char_now] = i
3434

35-
return counter
36-
"""
37-
I really take time to explain my solution, because I wanted to help people understand.
38-
If you like my answer, a star on GitHub I will really appreciated.
39-
https://github.com/wuduhren/leetcode-python
40-
"""
35+
return counter

meeting-rooms-ii.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ def minMeetingRooms(self, intervals):
5050

5151
return len(free_rooms)
5252

53-
"""
54-
I really take time to make the best solution, because I wanted to help people understand.
55-
If you like my answer, a star on GitHub I will really appreciated.
56-
https://github.com/wuduhren/leetcode-python
57-
"""
58-
5953

6054

6155

merge-two-sorted-lists.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,3 @@ def mergeTwoLists(self, l1, l2):
2626
curr.next = l2
2727

2828
return pre.next
29-
30-
"""
31-
I really take time to make the best solution, because I wanted to help people understand.
32-
If you like my answer, a star on GitHub I will really appreciated.
33-
https://github.com/wuduhren/leetcode-python
34-
"""

min-stack.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,4 @@ def getMin(self):
3030
# obj.push(x)
3131
# obj.pop()
3232
# param_3 = obj.top()
33-
# param_4 = obj.getMin()
34-
35-
"""
36-
I really take time to make the best solution, because I wanted to help people understand.
37-
If you like my answer, a star on GitHub I will really appreciated.
38-
https://github.com/wuduhren/leetcode-python
39-
"""
33+
# param_4 = obj.getMin()

moving-average-from-data-stream.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,3 @@ def next(self, val):
1515

1616
return self.sum/float(len(self.queue))
1717

18-
"""
19-
I really take time to make the best solution, because I wanted to help people understand.
20-
If you like my answer, a star on GitHub I will really appreciated.
21-
https://github.com/wuduhren/leetcode-python
22-
"""

network-delay-time.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,4 @@ def networkDelayTime(self, times, N, K):
5252
heapq.heappush(pq, (d+d2, nb)) #[2]
5353

5454
return max(dis.values()) if len(dis)==N else -1 #[5]
55-
"""
56-
I really take some time to explain my solution, because I wanted to help people understand.
57-
If you like my answer, a star on GitHub I will really appreciated.
58-
https://github.com/wuduhren/leetcode-python
59-
"""
55+

reverse-integer.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@ def reverse(self, x):
2020

2121
return x
2222

23-
"""
24-
I really take time to explain my solution, because I wanted to help people understand.
25-
If you like my answer, a star on GitHub I will really appreciated.
26-
https://github.com/wuduhren/leetcode-python
27-
"""

reverse-linked-list.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,3 @@ def reverseList(self, head):
1111

1212
return prev
1313

14-
"""
15-
I really take time to make the best solution, because I wanted to help people understand.
16-
If you like my answer, a star on GitHub I will really appreciated.
17-
https://github.com/wuduhren/leetcode-python
18-
"""

roman-to-integer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,4 @@ def romanToInt(self, s):
3737

3838
return counter
3939

40-
"""
41-
I really take time to explain my solution, because I wanted to help people understand.
42-
If you like my answer, a star on GitHub I will really appreciated.
43-
https://github.com/wuduhren/leetcode-python
44-
"""
40+

two-sum.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ def twoSum(self, nums, target):
1919
wanted[target-n] = i #[0]
2020
return []
2121

22-
"""
23-
I really take time to explain my solution, because I wanted to help people understand.
24-
If you like my answer, a star on GitHub I will really appreciated.
25-
https://github.com/wuduhren/leetcode-python
26-
"""

unique-email-addres.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,4 @@ def numUniqueEmails(self, emails):
6767
book.add(r)
6868
return len(book)
6969

70-
"""
71-
I really take time to make the best solution, because I wanted to help people understand.
72-
If you like my answer, a star on GitHub I will really appreciated.
73-
https://github.com/wuduhren/leetcode-python
74-
"""
70+

valid-parentheses.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@ def isValid(self, s):
1212
else:
1313
return False
1414

15-
"""
16-
I really take time to make the best solution, because I wanted to help people understand.
17-
If you like my answer, a star on GitHub I will really appreciated.
18-
https://github.com/wuduhren/leetcode-python
19-
"""
15+

0 commit comments

Comments
 (0)