Skip to content

Commit 0fb1fea

Browse files
committed
2020-08-22
1 parent c258f22 commit 0fb1fea

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def makeGood(self, s):
3+
"""
4+
:type s: str
5+
:rtype: str
6+
"""
7+
stack = []
8+
for ch in s:
9+
if not stack or abs(ord(stack[-1]) - ord(ch)) != 32:
10+
stack.append(ch)
11+
else:
12+
stack.pop()
13+
return "".join(ch for ch in stack)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def findKthBit(self, n, k):
3+
"""
4+
:type n: int
5+
:type k: int
6+
:rtype: str
7+
"""
8+
9+
def invert(s):
10+
res = ""
11+
for ch in s:
12+
if ch == "0":
13+
res += "1"
14+
else:
15+
res += "0"
16+
return res
17+
18+
i = 1
19+
s = "0"
20+
while i < n:
21+
s = s + "1" + invert(s)[::-1]
22+
i += 1
23+
if k - 1 < len(s):
24+
return s[k - 1]
25+
return s[k - 1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution(object):
2+
def maxNonOverlapping(self, nums, target):
3+
"""
4+
:type nums: List[int]
5+
:type target: int
6+
:rtype: int
7+
"""
8+
pre_sum = {0}
9+
res = 0
10+
s = 0
11+
for num in nums:
12+
s += num
13+
if s - target in pre_sum:
14+
res += 1
15+
s = 0
16+
pre_sum = {0}
17+
else:
18+
pre_sum.add(s)
19+
return res

0 commit comments

Comments
 (0)