Skip to content

Commit 58c7b5f

Browse files
committed
add python 16 17 18 19 20 solutions
1 parent 535df8f commit 58c7b5f

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def minimumSum(self, num):
3+
"""
4+
:type num: int
5+
:rtype: int
6+
"""
7+
res = []
8+
while num:
9+
res.append(num%10)
10+
num/=10
11+
res.sort()
12+
return res[0]*10+res[2]+ res[1]*10+res[3]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def balancedStringSplit(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
res, tmp = 0,0
8+
for char in s:
9+
if char == 'R':
10+
tmp += 1
11+
else:
12+
tmp -= 1
13+
if tmp == 0:
14+
res += 1
15+
return res
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def canPlaceFlowers(self, flowerbed, n):
3+
"""
4+
:type flowerbed: List[int]
5+
:type n: int
6+
:rtype: bool
7+
"""
8+
tmp = [0]+flowerbed+[0]
9+
for i in range(1,len(tmp)-1):
10+
if tmp[i-1] == 0 and tmp[i] == 0 and tmp[i+1] == 0:
11+
tmp[i] = 1
12+
n -= 1
13+
return n <= 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def partitionLabels(self, s):
3+
"""
4+
:type s: str
5+
:rtype: List[int]
6+
"""
7+
last = [0] * 26
8+
for i in range(len(s)):
9+
last[ord(s[i]) - ord('a')] = i
10+
res = []
11+
left,right = 0,0
12+
for i in range(len(s)):
13+
right = max(right, last[ord(s[i]) - ord('a')])
14+
if i == right:
15+
res.append(right - left + 1)
16+
left = i + 1
17+
return res
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def partitionString(self, s):
3+
"""
4+
:type s: str
5+
:rtype: int
6+
"""
7+
res = 1
8+
tmp = []
9+
for char in s:
10+
if char in tmp:
11+
tmp = [char]
12+
res +=1
13+
else:
14+
tmp.append(char)
15+
return res

0 commit comments

Comments
 (0)