Skip to content

Commit

Permalink
2019-05-27
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed May 27, 2019
1 parent 9c8bbdc commit 5010806
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 0254.因子的组合/0254-因子的组合.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution(object):
def getFactors(self, n):
"""
:type n: int
:rtype: List[List[int]]
"""
res = []
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
comb = sorted([i, n // i])
if comb not in res: #È¥ÖØ
res.append(comb)

for item in self.getFactors(n // i) :
comb = sorted([i] + item)
if comb not in res: #È¥ÖØ
res.append(comb)

return res
25 changes: 25 additions & 0 deletions 0318.最大单词长度乘积/0318-最大单词长度乘积.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution(object):
def maxProduct(self, words):
"""
:type words: List[str]
:rtype: int
"""
words = sorted(words, key = lambda x: -len(x))
# print words
from collections import Counter
dic = [Counter(item) for item in words]
# print dic
res = 0
l = len(words)
for i in range(l - 1):
for j in range(i + 1, l):
# print i, j, dic[i] & dic[j]
# if dic[i] & dic[j] == Counter():
flag = 0
for char in words[i]:
if char in dic[j]:
flag = 1
break
if flag == 0:
res = max(res, len(words[i]) *len(words[j]))
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution(object):
def countPrimeSetBits(self, L, R):
"""
:type L: int
:type R: int
:rtype: int
"""
# print 2 **14
prime = set([ 2, 3, 5, 7, 11, 13, 17, 19])

res = 0
for i in range(L, R + 1):
if bin(i).count("1") in prime:
res += 1
return res

17 changes: 17 additions & 0 deletions 0941.有效的山脉数组/0941-有效的山脉数组.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution(object):
def validMountainArray(self, A):
"""
:type A: List[int]
:rtype: bool
"""
if len(A) < 3:
return False

max_A_pos = A.index(max(A))
if max_A_pos in [0, len(A) - 1]:
return False

first, last = A[:max_A_pos + 1], A[max_A_pos:]
if len(first) != len(set(first)) or len(last) != len(set(last)):
return False
return first == sorted(first) and last == sorted(last)[::-1]

0 comments on commit 5010806

Please sign in to comment.