leetcode
文章平均质量分 56
xiaoling_000666
这个作者很懒,什么都没留下…
展开
-
python实现 LeetCode19——Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2017-12-29 00:19:36 · 170 阅读 · 0 评论 -
python实现 LeetCode40—— Combination Sum II
和上一个题很像,但是每个数字只能使用一次。class Solution(object): def combinationSum2(self, candidates, target): self.result=[] candidates.sort() start=0 val=[] self.backdate(ca...原创 2018-05-23 20:56:16 · 639 阅读 · 0 评论 -
python实现 LeetCode39——Combination Sum
利用递归的方式求得和为定值的数,如果目标值小于0,肯定不是解,就break。class Solution(object): def combinationSum(self, candidates, target): candidates = list(set(candidates)) sorted(candidates) self.resul...原创 2018-05-23 20:48:46 · 1020 阅读 · 0 评论 -
python实现 LeetCode36——Count and Say
count代表这个这个数一共有几个,利用count再加上这个位置的数,最终得到最后的结果class Solution(object): def countAndSay(self, n): string='1' while n>1: string=self.countStr(string) n=n-1 ...原创 2018-03-28 17:04:10 · 195 阅读 · 0 评论 -
python实现 LeetCode37——Sudoku Solver
数独游戏,用了dfs的深度优先树。25行和26行的else将该位置改为点,是在一次dfs中的,相当于在for循环中不断尝试c值中的赋值。如果所有的c值都不对的时候会进入27行的return false,然后再进入23行的赋值。class Solution(object): def solveSudoku(self, board): def isvaild(i,j): ...原创 2018-03-28 16:55:19 · 772 阅读 · 0 评论 -
python实现 LeetCode36——Valid Sudoku
利用set函数,查找某个元素是否在set中,更快class Solution(object): def isValidSudoku(self, board): s=set() list=board for i in range(9): for j in range(9): if list...原创 2018-03-26 20:16:32 · 388 阅读 · 0 评论 -
python实现 LeetCode34——Search for a Range
二分法找到target的位置,再判断前后的位置class Solution(object): def searchRange(self, nums, target): start=0 end=len(nums)-1 while start<=end and start>=0 and end<=len(nums)-1: ...原创 2018-03-21 20:11:12 · 262 阅读 · 0 评论 -
python实现 LeetCode35——Search Insert Position
自己开始写的代码,不过因为要多判断一次第一个数字,所以感觉不是很整洁,不过也通过了。class Solution(object): def searchInsert(self, nums, target): start=0 end=len(nums) if target<=nums[0]: return 0 ...原创 2018-03-21 18:57:45 · 158 阅读 · 0 评论 -
python实现 LeetCode33——Search in Rotated Sort
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the a...原创 2018-03-19 18:49:23 · 148 阅读 · 0 评论 -
python实现 LeetCode31——Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2018-01-05 10:21:49 · 522 阅读 · 0 评论 -
python实现 LeetCode43——Multiply Strings
先反序,在统计位数,取模是本位数,除十是进位的数。class Solution(object): def multiply(self, num1, num2): num1=num1[::-1] num2=num2[::-1] carry=0 sum='' arr=[0 for i in range(len(nu...原创 2018-05-23 23:09:00 · 559 阅读 · 1 评论