摘要: 思路: 声明矩阵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 人间烟火地三鲜 阅读(284) 评论(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 人间烟火地三鲜 阅读(220) 评论(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 人间烟火地三鲜 阅读(211) 评论(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 人间烟火地三鲜 阅读(214) 评论(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 人间烟火地三鲜 阅读(199) 评论(0) 推荐(0)
摘要: 思路: 指针i和j分别遍历nums1和nums2; 取两指针较小者追加到res中,较小指针后移,较大者不动; 若两指针相等,则两者都追加到res中,两指针均后移; i<m或j<n时,停止遍历,将两串之一剩余的部分有序序列追加到res中。注:本题提交的时候,程序不用return,另外本题必须在nums 阅读全文
posted @ 2020-04-17 22:59 人间烟火地三鲜 阅读(252) 评论(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 人间烟火地三鲜 阅读(161) 评论(0) 推荐(0)
摘要: 思路:折半查找,关键在于停止循环的条件。 1 class Solution(object): 2 def searchInsert(self, nums, target): 3 """ 4 :type nums: List[int] 5 :type target: int 6 :rtype: int 阅读全文
posted @ 2020-04-17 22:49 人间烟火地三鲜 阅读(201) 评论(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 len(num 阅读全文
posted @ 2020-04-17 22:47 人间烟火地三鲜 阅读(135) 评论(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 if 阅读全文
posted @ 2020-04-17 22:43 人间烟火地三鲜 阅读(127) 评论(0) 推荐(0)