Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 60b9e8b

Browse files
committed
leetcode刷题
1 parent 2241fb0 commit 60b9e8b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

卡牌分组.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#-*- coding:utf8 -*-
2+
#author : Lenovo
3+
#date: 2018/10/7
4+
def hasGroupsSizeX(deck):
5+
"""
6+
:type deck: List[int]
7+
:rtype: bool
8+
"""
9+
dic={}
10+
if len(deck)==1: return False
11+
if len(set(deck))==1: return True
12+
for one in deck:
13+
if one not in dic:
14+
dic[one]=1
15+
else:
16+
dic[one]+=1
17+
tem=1
18+
for j in range(2,max(dic.values())+1):
19+
#all函数 参数中所有满足条件则返回true
20+
if all(dic.values()[k]%j==0 for k in range(len(dic.values()))):
21+
tem=j
22+
return tem!=1
23+
24+
#[1,1,1,1,2,2,2,2,2,2] 第一次未通过 特例
25+
#[1,1,1,2,2,2,3,3]
26+
#说明如果具有大于1的公因子则也可以
27+
res=hasGroupsSizeX([1,1,1,1,2,2,2,2,2,2])
28+
print(res)

键盘行.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#-*-coding:utf8-*-
2+
#author : Lenovo
3+
#date: 2018/10/7
4+
def findWords(words):
5+
"""
6+
:type words: List[str]
7+
:rtype: List[str]
8+
"""
9+
one={'q','Q','w','W','e','E','r','R','t','T','y','Y','u','U','i','I','O','o','p','P'}
10+
two={'a','A','s','S','d','D','f','F','g','G','h','H','j','J','k','K','l','L'}
11+
three={'z','Z','x','X','c','C','v','V','b','B','n','N','m','M'}
12+
res=[]
13+
for word in words:
14+
if all(word[i] in one for i in range(len(word))) or all(word[i] in two for i in range(len(word))) or all(word[i] in three for i in range(len(word))):
15+
res.append(word)
16+
17+
return res
18+
19+
res=findWords(["Hello", "Alaska", "Dad", "Peace"])
20+
print(res)

0 commit comments

Comments
 (0)