Skip to content

Commit bc02a89

Browse files
committed
2019-06-15
1 parent 0524c01 commit bc02a89

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def findOcurrences(self, text, first, second):
3+
"""
4+
:type text: str
5+
:type first: str
6+
:type second: str
7+
:rtype: List[str]
8+
"""
9+
res = []
10+
text = text.split(" ")
11+
for i in range(len(text) - 2):
12+
if text[i] == first and text[i + 1] == second:
13+
res.append(text[i + 2])
14+
15+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def sumOfDigits(self, A):
3+
"""
4+
:type A: List[int]
5+
:rtype: int
6+
"""
7+
n = min(A)
8+
s = 0
9+
while n > 0:
10+
n, tmp = divmod(n, 10)
11+
s += tmp
12+
# print s
13+
return 1 - s % 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import heapq
2+
class Solution(object):
3+
def highFive(self, items):
4+
"""
5+
:type items: List[List[int]]
6+
:rtype: List[List[int]]
7+
"""
8+
record = dict()
9+
10+
for item in items:
11+
sd, sc = item[0], item[1]
12+
13+
if sd not in record:
14+
record[sd] = [sc]
15+
heapq.heapify(record[sd])
16+
else:
17+
heapq.heappush(record[sd], sc)
18+
if len(record[sd]) > 5:
19+
heapq.heappop(record[sd])
20+
print record[sd]
21+
res = []
22+
for key, val in record.items():
23+
res.append([key, sum(val) // 5])
24+
# print record
25+
return res
26+
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution(object):
2+
def permute(self, S):
3+
"""
4+
:type S: str
5+
:rtype: List[str]
6+
"""
7+
def generate(s, tmp):
8+
if not s:
9+
res.append(tmp[:])
10+
return
11+
if s[0].isalpha():
12+
generate(s[1:], tmp + s[0])
13+
else:
14+
for i in range(len(s)):
15+
if s[i] == "}":
16+
substring = s[1:i]
17+
break
18+
chars = substring.split(",")
19+
chars.sort()
20+
for char in chars:
21+
generate(s[i + 1:], tmp + char)
22+
res = []
23+
generate(S, "")
24+
25+
return res
26+

0 commit comments

Comments
 (0)