随笔分类 - leetcode
摘要:【转】https://blog.csdn.net/zhuanzhe117/article/details/72846939 有一座高度是10级台阶的楼梯,从下往上走,每跨一步只能向上1级或者2级台阶。要求用程序来求出一共有多少种走法。 如果每次走1级,需要走10步,结果可以表示成(1,1,1,1,1
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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],
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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]
阅读全文
摘要:一、使用内置函数 def toLowerCase(self, str: 'str') -> 'str': return str.lower() 28ms,12.4M class Solution: def toLowerCase(self, str: 'str') -> 'str': res = '
阅读全文
摘要:class Solution: def numUniqueEmails(self, emails: 'List[str]') -> 'int': accept = [] for email in emails: local = email.split('@')[0] domain = email.s
阅读全文
摘要: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
阅读全文