-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |