Skip to content

Commit e96fab6

Browse files
author
Jiayang Wu
committedNov 14, 2019
2019-11-13
1 parent c8002e5 commit e96fab6

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
 

‎.DS_Store

0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def findRightInterval(self, intervals):
3+
"""
4+
:type intervals: List[List[int]]
5+
:rtype: List[int]
6+
"""
7+
dic = {}
8+
for i, (start, end) in enumerate(intervals):
9+
dic[start] = i
10+
11+
res = [-1 for _ in range(len(intervals))]
12+
13+
l = [interval[0] for interval in intervals]
14+
l = sorted(l, key = lambda x:x)
15+
16+
for i, (start, end) in enumerate(intervals):
17+
idx = bisect.bisect_left(l, end)
18+
if idx < len(l):
19+
res[i] = dic[l[idx]]
20+
21+
return res
22+
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution(object):
2+
def licenseKeyFormatting(self, S, K):
3+
"""
4+
:type S: str
5+
:type K: int
6+
:rtype: str
7+
"""
8+
s = "".join(S.split("-")).upper()
9+
length_of_first_part = len(s) % K
10+
if not length_of_first_part:
11+
length_of_first_part = K
12+
13+
res = s[:length_of_first_part]
14+
for i in range(length_of_first_part, len(s), K):
15+
res += "-"
16+
res += s[i:i+K]
17+
return res
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution(object):
2+
def shortestWay(self, source, target):
3+
"""
4+
:type source: str
5+
:type target: str
6+
:rtype: int
7+
"""
8+
9+
import collections
10+
dicse = collections.Counter(source)
11+
dictt = collections.Counter(target)
12+
13+
for key, val in dictt.items():
14+
if dicse.get(key, 0) == 0:
15+
return -1
16+
17+
cnt = 0
18+
start, end = 0, 0
19+
i = 0
20+
while(i < len(target)):
21+
char = target[i]
22+
while(source[start] != char): #找起点,一定能找到
23+
start += 1
24+
end = start + 1
25+
26+
i += 1
27+
while(i < len(target) and end < len(source)):
28+
if source[end] == target[i]: #找最长的子序列
29+
i += 1
30+
end += 1
31+
32+
cnt += 1
33+
start = 0 #重置起点,为下一轮做准备
34+
35+
return cnt
36+
37+

0 commit comments

Comments
 (0)