Skip to content

Commit 2194e4d

Browse files
committedJun 21, 2020
2020-06-21
1 parent b71b283 commit 2194e4d

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed
 

‎1452.收藏清单/1452-收藏清单.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,5 @@ def peopleIndexes(self, favoriteCompanies):
44
:type favoriteCompanies: List[List[str]]
55
:rtype: List[int]
66
"""
7-
from collections import defaultdict
8-
9-
dic = defaultdict(set)
10-
11-
for i, l in enumerate(favoriteCompanies):
12-
for company in l:
13-
dic[company].add(i)
14-
15-
res = []
16-
for i, l in enumerate(favoriteCompanies):
17-
s = dic[l[0]]
18-
for company in l[1:]:
19-
# print i,s, dic[company]
20-
s = s & dic[company]
21-
# print s
22-
# print i, s
23-
if len(s) == 1:
24-
res.append(i)
25-
26-
return res
27-
7+
s = [set(l) for l in favoriteCompanies]
8+
return [i for i, s1 in enumerate(s) if not any(s1 < s2 for s2 in s)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def isPrefixOfWord(self, sentence, searchWord):
3+
"""
4+
:type sentence: str
5+
:type searchWord: str
6+
:rtype: int
7+
"""
8+
words = sentence.split()
9+
for i, word in enumerate(words):
10+
if word.startswith(searchWord):
11+
return i + 1
12+
13+
return -1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def maxVowels(self, s, k):
3+
"""
4+
:type s: str
5+
:type k: int
6+
:rtype: int
7+
"""
8+
vowels = "aeiou"
9+
10+
start = 0
11+
res = 0
12+
tmp = 0
13+
for end in range(len(s)):
14+
if s[end] in vowels:
15+
tmp += 1
16+
while end - start + 1 > k:
17+
if s[start] in vowels:
18+
tmp -= 1
19+
start += 1
20+
res = max(res, tmp)
21+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode(object):
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution(object):
8+
def pseudoPalindromicPaths (self, root):
9+
"""
10+
:type root: TreeNode
11+
:rtype: int
12+
"""
13+
self.res = 0
14+
15+
def dfs(node, path):
16+
if not node:
17+
return
18+
19+
path = path + [node.val]
20+
if not node.left and not node.right:
21+
if self.hasPalindromic(path):
22+
self.res += 1
23+
24+
dfs(node.left, path)
25+
dfs(node.right, path)
26+
27+
dfs(root, [])
28+
return self.res
29+
30+
def hasPalindromic(self, nums):
31+
from collections import Counter
32+
33+
dic = Counter(nums)
34+
35+
oddCnt = 0
36+
for val in dic.values():
37+
if val % 2:
38+
oddCnt += 1
39+
40+
return oddCnt <= 1
41+
42+
43+
44+
45+

0 commit comments

Comments
 (0)