![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
公众号-程序猿刘先森
关注微信公众号" 程序猿刘先森", 共同学习~
展开
-
LeetCode OJ 系列之219 Contains Duplicate II --Python
Problem:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis a原创 2015-11-23 14:49:36 · 401 阅读 · 0 评论 -
LeetCode OJ 系列之122 Best Time to Buy and Sell Stock II --Python
Problem:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you li原创 2015-11-26 09:21:04 · 425 阅读 · 0 评论 -
LeetCode OJ 系列之1 Two Sum --Python
Problem:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to t原创 2015-11-27 12:02:31 · 381 阅读 · 0 评论 -
LeetCode OJ 系列之62 Unique Paths --Python
Problem: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原创 2015-11-27 12:04:08 · 339 阅读 · 0 评论 -
LeetCode OJ 系列之63 Unique Paths II --Python
Problem:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respecti原创 2015-11-27 12:05:38 · 428 阅读 · 0 评论 -
LeetCode OJ 系列之228 Summary Ranges --Python
Problem:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].Answer:class Solution(object):原创 2015-11-16 09:11:30 · 1015 阅读 · 0 评论 -
LeetCode OJ 系列之66 Plus One --Python
Problem:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Answ原创 2015-12-09 01:32:51 · 1180 阅读 · 0 评论 -
LeetCode OJ 系列之118 Pascal's Triangle --Python
Problem:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2015-12-09 01:28:59 · 635 阅读 · 0 评论 -
LeetCode OJ 系列之75 Sort Colors --Python
Problem:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use原创 2015-12-09 01:37:59 · 705 阅读 · 0 评论 -
LeetCode OJ 系列之165 Compare Version Numbers --Python
Problem:Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-原创 2015-12-09 01:40:18 · 849 阅读 · 0 评论 -
LeetCode OJ 系列之121 Best Time to Buy and Sell Stock --Python
Problem:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share原创 2015-11-26 09:10:53 · 417 阅读 · 0 评论 -
LeetCode OJ 系列之169 Majority Element --Python
Problem:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the maj原创 2015-11-24 09:06:41 · 800 阅读 · 0 评论 -
LeetCode OJ 系列之287 Find the Duplicate Number --Python
Problem:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplic原创 2015-11-23 22:00:40 · 399 阅读 · 0 评论 -
LeetCode OJ 系列之283 Move Zeroes --Python
Problem:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], aft原创 2015-11-17 09:00:44 · 1104 阅读 · 0 评论 -
LeetCode OJ 系列之27 Remove Element --Python
Problem:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the ne原创 2015-11-17 13:16:56 · 576 阅读 · 0 评论 -
LeetCode OJ 系列之58 Length of Last Word --Python
Problem:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.原创 2015-12-09 01:36:21 · 757 阅读 · 0 评论 -
LeetCode OJ 系列之151 Reverse Words in a String --Python
Problem:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to so原创 2015-12-09 01:42:17 · 494 阅读 · 0 评论 -
LeetCode OJ 系列之65 Valid Number --Python
Problem:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem state原创 2015-12-09 01:34:44 · 1141 阅读 · 0 评论 -
LeetCode OJ 系列之35 Search Insert Position --Python
Problem:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates原创 2015-11-16 22:16:52 · 419 阅读 · 0 评论 -
LeetCode OJ 系列之217 Contains Duplicate --Python
Problem:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if ever原创 2015-11-23 14:30:14 · 697 阅读 · 0 评论 -
LeetCode OJ 系列之26 Remove Duplicates from Sorted Array --Python
Problem:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this原创 2015-11-18 17:02:34 · 446 阅读 · 0 评论 -
LeetCode OJ 系列之78 Subsets --Python
Problem:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subset原创 2015-11-18 22:07:50 · 1804 阅读 · 0 评论 -
LeetCode OJ 系列之73 Set Matrix Zeroes --Python
Problem:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Answer:class Solution(object): def setZeroes(self, matrix): """原创 2015-12-09 01:31:29 · 484 阅读 · 0 评论