摘要:
代码一: 1 class Solution(object): 2 def rotate(self, nums, k): 3 """ 4 :type nums: List[int] 5 :type k: int 6 :rtype: None Do not return anything, modify 阅读全文
posted @ 2020-04-21 23:24
人间烟火地三鲜
阅读(118)
评论(0)
推荐(0)
摘要:
list、set、str的转换: str转list:list(str) list转set:set(list) set转list:list(set) 注:list转set时会自动去重! 将list[str] digits转成list[int]: 法一:[ int(i) for i in digits 阅读全文
posted @ 2020-04-21 23:18
人间烟火地三鲜
阅读(182)
评论(0)
推荐(0)
摘要:
思路: 想到:prices中一列数字,任取一个为买入价格buy,在其右边任取一个为卖出价格sell;取[buy,...,sell]区间中相邻数字之差,这些差值求和为sum,则必有sell-buy = sum;本题中求最大收益,所以遍历prices,找到prices[i]-prices[i-1] > 阅读全文
posted @ 2020-04-21 23:13
人间烟火地三鲜
阅读(173)
评论(0)
推荐(0)
摘要:
给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。 在杨辉三角中,每个数是它左上方和右上方的数的和。 1 class Solution(object): 2 def getRow(self, rowIndex): 3 """ 4 :type rowIndex: int 5 :rty 阅读全文
posted @ 2020-04-21 23:08
人间烟火地三鲜
阅读(130)
评论(0)
推荐(0)
摘要:
给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。 在杨辉三角中,每个数是它左上方和右上方的数的和。 1 class Solution(object): 2 def generate(self, numRows): 3 """ 4 :type numRows: int 5 :r 阅读全文
posted @ 2020-04-21 23:06
人间烟火地三鲜
阅读(140)
评论(0)
推荐(0)
摘要:
代码一: 1 class Solution(object): 2 def removeElement(self, nums, val): 3 """ 4 :type nums: List[int] 5 :type val: int 6 :rtype: int 7 """ 8 if nums == [ 阅读全文
posted @ 2020-04-21 23:02
人间烟火地三鲜
阅读(79)
评论(0)
推荐(0)
摘要:
1 class Solution(object): 2 def removeDuplicates(self, nums): 3 """ 4 :type nums: List[int] 5 :rtype: int 6 """ 7 i = 0 8 while i < len(nums) - 1: 9 i 阅读全文
posted @ 2020-04-21 22:58
人间烟火地三鲜
阅读(154)
评论(0)
推荐(0)
摘要:
通常可以写出的二分法:mid = (start + end) / 2; 另一种写法:mid = start + (end - start) / 2,可防止 (start + end) 溢出。 代码一: 1 class Solution(object): 2 def search(self, nums 阅读全文
posted @ 2020-04-21 22:54
人间烟火地三鲜
阅读(186)
评论(0)
推荐(0)
摘要:
1 # The guess API is already defined for you. 2 # @param num, your guess 3 # @return -1 if my number is lower, 1 if my number is higher, otherwise ret 阅读全文
posted @ 2020-04-21 22:49
人间烟火地三鲜
阅读(173)
评论(0)
推荐(0)
摘要:
1 # The isBadVersion API is already defined for you. 2 # @param version, an integer 3 # @return a bool 4 # def isBadVersion(version): 5 6 class Soluti 阅读全文
posted @ 2020-04-21 22:48
人间烟火地三鲜
阅读(115)
评论(0)
推荐(0)

浙公网安备 33010602011771号