Skip to content

Commit 5010806

Browse files
committedMay 27, 2019
2019-05-27
1 parent 9c8bbdc commit 5010806

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution(object):
2+
def getFactors(self, n):
3+
"""
4+
:type n: int
5+
:rtype: List[List[int]]
6+
"""
7+
res = []
8+
for i in range(2, int(n ** 0.5) + 1):
9+
if n % i == 0:
10+
comb = sorted([i, n // i])
11+
if comb not in res: #È¥ÖØ
12+
res.append(comb)
13+
14+
for item in self.getFactors(n // i) :
15+
comb = sorted([i] + item)
16+
if comb not in res: #È¥ÖØ
17+
res.append(comb)
18+
19+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution(object):
2+
def maxProduct(self, words):
3+
"""
4+
:type words: List[str]
5+
:rtype: int
6+
"""
7+
words = sorted(words, key = lambda x: -len(x))
8+
# print words
9+
from collections import Counter
10+
dic = [Counter(item) for item in words]
11+
# print dic
12+
res = 0
13+
l = len(words)
14+
for i in range(l - 1):
15+
for j in range(i + 1, l):
16+
# print i, j, dic[i] & dic[j]
17+
# if dic[i] & dic[j] == Counter():
18+
flag = 0
19+
for char in words[i]:
20+
if char in dic[j]:
21+
flag = 1
22+
break
23+
if flag == 0:
24+
res = max(res, len(words[i]) *len(words[j]))
25+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution(object):
2+
def countPrimeSetBits(self, L, R):
3+
"""
4+
:type L: int
5+
:type R: int
6+
:rtype: int
7+
"""
8+
# print 2 **14
9+
prime = set([ 2, 3, 5, 7, 11, 13, 17, 19])
10+
11+
res = 0
12+
for i in range(L, R + 1):
13+
if bin(i).count("1") in prime:
14+
res += 1
15+
return res
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution(object):
2+
def validMountainArray(self, A):
3+
"""
4+
:type A: List[int]
5+
:rtype: bool
6+
"""
7+
if len(A) < 3:
8+
return False
9+
10+
max_A_pos = A.index(max(A))
11+
if max_A_pos in [0, len(A) - 1]:
12+
return False
13+
14+
first, last = A[:max_A_pos + 1], A[max_A_pos:]
15+
if len(first) != len(set(first)) or len(last) != len(set(last)):
16+
return False
17+
return first == sorted(first) and last == sorted(last)[::-1]

0 commit comments

Comments
 (0)
Please sign in to comment.