Time: Jun 09th, 2019 @ 10:30 AM - 12:00 AM (GMT+8)
Exciting~第一次排名进top100!
这一次全用python写的,写起来快了不少...
5083. Occurrences After Bigram
送分题。
1 2 3 4 5 6 7 8
classSolution: deffindOcurrences(self, text: str, first: str, second: str) -> List[str]: l = text.split() ret = [] for i inrange(len(l) - 2): if l[i] == first and l[i + 1] == second: ret.append(l[i + 2]) return ret
5087. Letter Tile Possibilities
tiles的长度最长也就是7,dfs就可以了,使用set来去重。
1 2 3 4 5 6 7 8 9 10 11 12 13
classSolution: ans = set() defdfs(self, s: str, cur: str): self.ans.add(cur) for i inrange(len(s)): self.dfs(s[:i] + s[i + 1:], cur + s[i]) defnumTilePossibilities(self, tiles: str) -> int: self.ans = set() for i inrange(len(tiles)): self.dfs(tiles[:i] + tiles[i + 1:], tiles[i]) returnlen(self.ans)
defsmallestSubsequence(self, text: str) -> str: d = {x: [] for x inset(text)} for i inrange(len(text)): d[text[i]].append(i) order = sorted(list(d.keys())) check = {x:Falsefor x in order}
ans = "" cur = -1 for i inrange(len(order)): for x in order: ifnot check[x]: pos = bisect.bisect(d[x], cur) if pos == len(d[x]): continue new_cur = d[x][pos] ifall([d[y][-1] >= new_cur for y in order ifnot check[y]]): break