上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 51 下一页
摘要: 思路:双指针。 1 class Solution(object): 2 def twoSum(self, numbers, target): 3 """ 4 :type numbers: List[int] 5 :type target: int 6 :rtype: List[int] 7 """ 阅读全文
posted @ 2020-04-21 22:46 人间烟火地三鲜 阅读(130) 评论(0) 推荐(0)
摘要: 思路: 用二分查找,端点值从0和x开始,当两端点数相邻了停止循环。若停止循环了,则返回左端点——较小者。 1 class Solution(object): 2 def mySqrt(self, x): 3 """ 4 :type x: int 5 :rtype: int 6 """ 7 if x 阅读全文
posted @ 2020-04-21 22:43 人间烟火地三鲜 阅读(236) 评论(0) 推荐(0)
摘要: list[] 和 list[:] 的理解 list“赋值”时会用到list2 = list1 或者 list2[:] = list1,前者两个名字指向同一个对象,后者两个名字指向不同对象。理解如下: 首先,python中没有赋值的说法,只有名称到对象的引用; list2 = list1是把list1 阅读全文
posted @ 2020-04-21 22:35 人间烟火地三鲜 阅读(3461) 评论(0) 推荐(0)
摘要: 思路: 声明矩阵list; 返回按曼哈顿距离排序的list; 1 class Solution(object): 2 3 def allCellsDistOrder2(self, R, C, r0, c0): 4 """ 5 :type R: int 6 :type C: int 7 :type r 阅读全文
posted @ 2020-04-17 23:19 人间烟火地三鲜 阅读(286) 评论(0) 推荐(0)
摘要: 思路:1、设置res=[],extra[];2、遍历arr2,统计arr1中arr2[i]的个数num;3、在res中追加num个arr2[i];4、遍历arr1,将没出现在arr2中的元素添加到extra中;5、将extra升序排列,返回res+extra。 1 class Solution(ob 阅读全文
posted @ 2020-04-17 23:15 人间烟火地三鲜 阅读(222) 评论(0) 推荐(0)
摘要: 思路:1、降序排列nums;2、不断从nums中取出最大元素追加到res中,直到res元素的和大于nums;3、返回res。 1 class Solution(object): 2 def minSubsequence(self, nums): 3 """ 4 :type nums: List[in 阅读全文
posted @ 2020-04-17 23:12 人间烟火地三鲜 阅读(213) 评论(0) 推荐(0)
摘要: 方法一:思路见注释。 1 class Solution(object): 2 def merge(self, intervals): 3 """ 4 :type intervals: List[List[int]] 5 :rtype: List[List[int]] 6 """ 7 if len(i 阅读全文
posted @ 2020-04-17 23:07 人间烟火地三鲜 阅读(215) 评论(0) 推荐(0)
摘要: 思路: 1、将prices升序排列;2、用price遍历排序后的prices,取price在原list中的下标i;3、在原list中截取下标i之后的元素,取其中最大值max(temp[i:]);4、计算当前利润:max(temp[i:]) - price,存入ans[]中;5、返回ans中的最大值。 阅读全文
posted @ 2020-04-17 23:01 人间烟火地三鲜 阅读(200) 评论(0) 推荐(0)
摘要: 思路: 指针i和j分别遍历nums1和nums2; 取两指针较小者追加到res中,较小指针后移,较大者不动; 若两指针相等,则两者都追加到res中,两指针均后移; i<m或j<n时,停止遍历,将两串之一剩余的部分有序序列追加到res中。注:本题提交的时候,程序不用return,另外本题必须在nums 阅读全文
posted @ 2020-04-17 22:59 人间烟火地三鲜 阅读(254) 评论(0) 推荐(0)
摘要: 思路: 将原list中的数字拼接成字符串res;将int(res) + 1转成list。 1 class Solution(object): 2 def plusOne(self, digits): 3 """ 4 :type digits: List[int] 5 :rtype: List[int 阅读全文
posted @ 2020-04-17 22:53 人间烟火地三鲜 阅读(163) 评论(0) 推荐(0)
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 51 下一页