Skip to content

Commit 7689c75

Browse files
Chris WuChris Wu
authored andcommitted
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

0 commit comments

Comments
 (0)