
leetcode_python
文章平均质量分 81
橘子oly
hhhh~越努力越幸运~~~~
展开
-
leetcode06_ZigZagConversion
一.问题描述ZigZagConversion:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibi原创 2016-09-11 11:34:01 · 268 阅读 · 0 评论 -
leetcode34_Search for a Range
一.问题描述Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target i原创 2016-11-01 09:33:31 · 305 阅读 · 0 评论 -
leetcode50_Pow(x, n)
一.问题描述Implement pow(x, n).实现指数乘法。二.代码编写首先想到的其实就是把n不断拆分成n/2,但是想歪了,可能沉浸在大数乘法那个题里,然后发现其实小数乘大数比两个相等的数运算复杂度低一点,所以就否定了这个想法。但看了tags是二分的思想,后来一想其实重点不在于每次运算的复杂度,而在于二分能将运算的次数由O(N)降低到O(logN)。所以其实这原创 2016-11-30 21:29:44 · 438 阅读 · 0 评论 -
leetcode39&40_Combination Sum& CombinationSumII
一.问题描述Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C un原创 2016-11-12 11:51:43 · 324 阅读 · 0 评论 -
leetcode42_Trapping Rain Water
一.问题描述Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,原创 2016-11-20 16:48:59 · 309 阅读 · 0 评论 -
leetcode56&57_Merge Intervals&Insert Interval
一、问题描述Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]二、代码编写 这个算法思想很简单,只要将list按照interval的s原创 2016-12-11 20:22:53 · 328 阅读 · 0 评论 -
leetcode41_First Missing Positive
一.问题描述给定一组integers,找出其中最小的缺失的正整数值,要求时间复杂度为O(n),空间复杂度为O(1)。二.代码编写时间复杂度为O(n)意味着不能直接对list进行排序O(NlogN),空间复杂度为常数意味着不能新建一个list。常数空间,我们应该想到直接swap,将相应得到数字m放到list的(m-1)的位置上。全部交换完毕后,返回list中第一个不满原创 2016-11-20 15:58:15 · 364 阅读 · 0 评论 -
leetcode51&52 N-Queens
一.问题描述The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-que原创 2016-12-04 15:10:16 · 347 阅读 · 0 评论 -
★leetcode43_Multiply Strings
一.问题描述实现字符串的乘法,不能直接将字符串转化成int哦~二.代码编写首先想到的方法就是根据我们平时手算乘法的方法来计算,本质上就是移位相乘相加~但是时间复杂度是O(N^2)。代码如下:'''@ author: wttttt at 2016.10.29@ problem description see: https://leetcode.com/prob原创 2016-11-22 20:14:11 · 574 阅读 · 0 评论 -
★leetcode44_Wildcard Matching
一.问题描述Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching sh原创 2016-11-24 09:55:52 · 469 阅读 · 0 评论 -
★leetcode45_Jump Game II
一.问题描述Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.原创 2016-11-25 17:07:27 · 362 阅读 · 0 评论 -
leetcode60_Permutation Sequence
一、问题描述The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132"原创 2016-12-16 15:44:02 · 392 阅读 · 0 评论 -
leetcode62&63&64_Unique Paths
一、问题描述A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2016-12-20 21:35:48 · 474 阅读 · 0 评论 -
leetcode73_ Set Matrix Zeroes
问题描述Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.代码编写*很明显是遍历的思想,但是做不到一遍做完所有,至少要两遍。 *于是想到先遍历行,再遍历列。为节省时间,在遍历列的时候,需要置零的列就不再考虑已经被置零的行。 *我的思路问题就在于只考虑了优化时间复原创 2017-02-27 20:37:22 · 541 阅读 · 0 评论 -
leetcode33_Search in Rotated Sorted Array
一.问题描述Suppose a sorted array 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原创 2016-10-29 17:35:54 · 284 阅读 · 0 评论 -
leetcode32_Longest Valid Parentheses
一.问题描述Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring原创 2016-10-29 09:54:44 · 265 阅读 · 0 评论 -
leetcode22_Generate Parentheses
一.题目描述Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()原创 2016-10-19 10:01:20 · 243 阅读 · 0 评论 -
leetcode9_Palindrome Number
一.问题描述Palindrome Number Determine whether an integer is a palindrome. Do thiswithout extra space.spoilers:Some hints:Could negative integers be palindromes? (ie, -1)If原创 2016-09-12 20:47:11 · 224 阅读 · 0 评论 -
★leetcode05_Longest Palindromic Substring
一.问题描述Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest pal原创 2016-09-10 17:03:02 · 570 阅读 · 0 评论 -
leetcode01_TwoSum
一.问题描述Two Sum:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.原创 2016-09-03 20:14:08 · 303 阅读 · 0 评论 -
leetcode03_Longest Substring Without Repeating Characters
一.问题描述Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is原创 2016-09-04 09:54:24 · 399 阅读 · 0 评论 -
★leetcode04_Median of Two Sorted Arrays
一.问题描述Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexi原创 2016-09-04 12:07:04 · 811 阅读 · 0 评论 -
leetcode11_Container With Most Water
一.问题描述Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (原创 2016-09-18 16:17:08 · 288 阅读 · 0 评论 -
★leetcode10_Regular Expression Matching[附动态规划]
一.问题描述Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the ent原创 2016-09-18 15:21:51 · 3583 阅读 · 1 评论 -
leetcode15&16_3Sum&4Sum
一.问题描述Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must原创 2016-10-05 15:17:28 · 270 阅读 · 0 评论 -
leetcode23_Merge k Sorted Lists
一.问题描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k条有序链表,返回一条有序链表二.算法思想有两种思路:1)利用二路归并的思想,将k条有序链条两两进行二路归并,一共需要logk次合并后得到最终链表。显然原创 2016-10-20 21:43:04 · 224 阅读 · 0 评论 -
leetcode27_Remove Element
一.问题描述Given an array and a value, remove all instances of that valuein place and return the new length.Do not allocate extra space for another array, you must do this in place with constan原创 2016-10-24 18:51:30 · 202 阅读 · 0 评论 -
leetcode28_Implement strStr()
一.问题描述Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.二.代码编写 最基本的想法就是,为两个字符串指定两个指针,相同则两个指针后移,不同则子串回退到0,母串往前原创 2016-10-24 19:07:08 · 196 阅读 · 0 评论 -
leetcode21_Merge Two Sorted Lists
一.问题描述 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. #合并两个有序链表,当然要求结果也是有序链表#Defini原创 2016-10-17 14:25:21 · 206 阅读 · 0 评论 -
leetcode36&37_SudukuSolver
36题:一.问题描述Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.原创 2016-11-07 15:05:09 · 366 阅读 · 0 评论 -
leetcode29_Divide Two Integers
一.问题描述Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.实现两个int的除法,代码中不能使用乘、除和取余操作,溢出时返回max_int。二.代码编写 最基原创 2016-10-24 20:48:46 · 333 阅读 · 0 评论