Skip to content

Commit 1e08f64

Browse files
committed
add 26 784 KMP
1 parent b25c4ca commit 1e08f64

12 files changed

+191
-0
lines changed

118.pascals-triangle.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 118.pascals-triangle.py
6+
# @Software: PyCharm
7+
8+
19
class Solution:
210
def generate(self, numRows):
311
"""
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/26 14:56
3+
# @Author : xulzee
4+
5+
# @File : 122. Best Time to Buy and Sell Stock II.py
6+
# @Software: PyCharm
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/26 11:47
3+
# @Author : xulzee
4+
5+
# @File : 26. Remove Duplicates from Sorted Array.py
6+
# @Software: PyCharm
7+
from typing import List
8+
9+
10+
class Solution:
11+
# pop
12+
def removeDuplicates1(self, nums: List[int]) -> int:
13+
j = 0
14+
remove_list = []
15+
for i in range(1, len(nums)):
16+
if nums[i] == nums[j]:
17+
remove_list.append(i)
18+
j = i
19+
# print(remove_list)
20+
for i in remove_list[::-1]:
21+
nums.pop(i)
22+
return len(nums)
23+
24+
# swap
25+
def removeDuplicates(self, nums: List[int]) -> int:
26+
j = 1
27+
if len(nums) > 0:
28+
for i in range(1, len(nums)):
29+
if nums[i] != nums[i - 1]:
30+
nums[j] = nums[i]
31+
j += 1
32+
else:
33+
j = 0
34+
return j
35+
36+
37+
if __name__ == '__main__':
38+
A = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4]
39+
print(Solution().removeDuplicates(A))
40+
print(A)

371.sum-of-two-integers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 371.sum-of-two-integers.py
6+
# @Software: PyCharm
7+
18
class Solution:
29
def getSum(self, a, b):
310
"""

509.fibonacci-number.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 509.fibonacci-number.py
6+
# @Software: PyCharm
7+
8+
19
class Solution:
210
def fib1(self, N):
311
"""

521.longest-uncommon-subsequence-i.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 521.longest-uncommon-subsequence-i.py
6+
# @Software: PyCharm
7+
8+
19
class Solution:
210
def findLUSlength(self, a, b):
311
"""

784.Letter Case Permutation.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 784.Letter Case Permutation.py
6+
# @Software: PyCharm
7+
8+
9+
class Solution:
10+
def letterCasePermutation(self, S: 'str') -> 'List[str]':
11+
result = []
12+
if S == "":
13+
return [""]
14+
print(result)
15+
for i in S:
16+
if i.isalpha():
17+
if result == []:
18+
result.append(i.lower())
19+
result.append(i.upper())
20+
else:
21+
temp = []
22+
temp = result[:]
23+
for j in range(len(result)):
24+
result[j] += i.lower()
25+
temp[j] += i.upper()
26+
result = result + temp
27+
28+
else:
29+
if result == []:
30+
result.append(i)
31+
else:
32+
for j in range(len(result)):
33+
result[j] += i
34+
return result
35+
36+
37+
if __name__ == '__main__':
38+
S = "a1b2"
39+
print(Solution().letterCasePermutation(S))

806.repeated_n_times.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 806.repeated_n_times.py
6+
# @Software: PyCharm
7+
8+
19
class Solution:
210
def repeatedNTimes1(self, A):
311
"""

933.number-of-recent-calls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 933.number-of-recent-calls.py
6+
# @Software: PyCharm
7+
18
import collections
29

310

961.number_of_lines.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/25 11:46
3+
# @Author : xulzee
4+
5+
# @File : 961.number_of_lines.py
6+
# @Software: PyCharm
7+
8+
19
import math
210
class Solution:
311
def numberOfLines1(self, widths, S):

0 commit comments

Comments
 (0)