随笔分类 -  leetcode

摘要:【转】https://blog.csdn.net/zhuanzhe117/article/details/72846939 有一座高度是10级台阶的楼梯,从下往上走,每跨一步只能向上1级或者2级台阶。要求用程序来求出一共有多少种走法。 如果每次走1级,需要走10步,结果可以表示成(1,1,1,1,1 阅读全文
posted @ 2022-04-28 14:14 bluedream1000 编辑
摘要:class Solution: def hammingDistance(self, x: int, y: int) -> int: z = x^y z = (z&0x55555555)+((z>>1)&0x55555555) z = (z&0x33333333)+((z>>2)&0x33333333 阅读全文
posted @ 2019-03-01 13:28 bluedream1000 阅读(172) 评论(0) 推荐(0) 编辑
摘要:class Solution: def diStringMatch(self, S: str) -> List[int]: A=[i for i in range(len(S)+1)] res = A for index,s in enumerate(S): if s is 'I': A[index 阅读全文
posted @ 2019-02-28 10:55 bluedream1000 阅读(129) 评论(0) 推荐(0) 编辑
摘要:class Solution: def judgeCircle(self, moves: str) -> bool: u,d,l,r = 0,0,0,0 for move in moves: if move is 'U': u += 1 elif move is 'D': d += 1 elif m 阅读全文
posted @ 2019-02-28 10:11 bluedream1000 阅读(140) 评论(0) 推荐(0) 编辑
摘要:class Solution: def calcu(self,ele:List[str],loc): index_p = [-1]*2 #只记录离R最近位置的p和B(左右) index_B = [-1]*2 left,right = 0,0 for i in range(len(ele)): if 阅读全文
posted @ 2019-02-27 14:53 bluedream1000 阅读(182) 评论(0) 推荐(0) 编辑
摘要:class Solution: def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]: for a in A: first = 0 last = len(a)-1 while first<last: a[first], 阅读全文
posted @ 2019-02-27 10:43 bluedream1000 阅读(114) 评论(0) 推荐(0) 编辑
摘要:class Solution: def sortArrayByParity(self, A: List[int]) -> List[int]: first = 0 last = len(A)-1 while first<last: m = A[first] n = A[last] if (m&1 i 阅读全文
posted @ 2019-02-27 09:46 bluedream1000 阅读(133) 评论(0) 推荐(0) 编辑
摘要:class Solution: def sortedSquares(self, A: List[int]) -> List[int]: sqr = [] for a in A: sqr.append((a)**2) return sorted(sqr) 184ms,15.2M 优化一: class 阅读全文
posted @ 2019-02-25 14:36 bluedream1000 阅读(159) 评论(0) 推荐(0) 编辑
摘要:class Solution: def repeatedNTimes(self, A: List[int]) -> int: if len(A)&1 > 0: return -1 aa = set(A) bb = {} for a in aa: bb[a] = 0 for i in A: bb[i] 阅读全文
posted @ 2019-02-25 13:30 bluedream1000 阅读(162) 评论(0) 推荐(0) 编辑
摘要:一、使用内置函数 def toLowerCase(self, str: 'str') -> 'str': return str.lower() 28ms,12.4M class Solution: def toLowerCase(self, str: 'str') -> 'str': res = ' 阅读全文
posted @ 2019-02-22 09:52 bluedream1000 阅读(139) 评论(0) 推荐(0) 编辑
摘要:class Solution: def numUniqueEmails(self, emails: 'List[str]') -> 'int': accept = [] for email in emails: local = email.split('@')[0] domain = email.s 阅读全文
posted @ 2019-02-21 10:38 bluedream1000 阅读(125) 评论(0) 推荐(0) 编辑
摘要:You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of ston 阅读全文
posted @ 2019-02-19 10:59 bluedream1000 阅读(168) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示