Skip to content

Commit defbc1e

Browse files
committed
2020-03-08
1 parent 8abe861 commit defbc1e

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution(object):
2+
def generateTheString(self, n):
3+
"""
4+
:type n: int
5+
:rtype: str
6+
"""
7+
if n % 2:
8+
return "a" * n
9+
return "a" * (n - 1) + "b"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def numTimesAllBlue(self, light):
3+
"""
4+
:type light: List[int]
5+
:rtype: int
6+
"""
7+
res = 0
8+
maxx = 0
9+
for i in range(len(light)):
10+
maxx = max(light[i] - 1, maxx)
11+
if i == maxx:
12+
res += 1
13+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution(object):
2+
def numOfMinutes(self, n, headID, manager, informTime):
3+
"""
4+
:type n: int
5+
:type headID: int
6+
:type manager: List[int]
7+
:type informTime: List[int]
8+
:rtype: int
9+
"""
10+
from collections import defaultdict, deque
11+
layer = defaultdict(set)
12+
13+
for i in range(n):
14+
layer[manager[i]].add(i) # key is the boss, val is the sub
15+
16+
self.res = 0
17+
18+
def dfs(hid, time):
19+
if hid not in layer:
20+
self.res = max(self.res, time)
21+
return
22+
23+
for sub in layer[hid]:
24+
dfs(sub, time + informTime[hid])
25+
26+
dfs(headID, 0)
27+
return self.res
28+
29+

0 commit comments

Comments
 (0)