Leetcode
IT莫莫
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode 3. Longest Substring Without Repeating Characters
link:https://leetcode.com/problems/longest-substring-without-repeating-characters/description/Given a string, find the length of the longest substring without repeating characters.Example 1:Inp...原创 2018-09-02 00:49:36 · 175 阅读 · 0 评论 -
Leetcode 29. Divide Two Integers
Given two integersdividendanddivisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividingdividendbydivisor.The integer division sho...原创 2019-03-26 06:57:47 · 140 阅读 · 0 评论 -
Leetcode 30. Substring with Concatenation of All Words
You are given a string,s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) insthat is a concatenation of each word inwordsexactly once and wi...原创 2019-03-26 10:08:48 · 125 阅读 · 0 评论 -
Leetcode 25:Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.kis a positive integer and is less than or equal to the length of the linked list. If the number of ...原创 2019-03-24 07:40:55 · 202 阅读 · 0 评论 -
Leetcode 26. Remove Duplicates from Sorted Array
Given a sorted arraynums, remove the duplicatesin-placesuch that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this bymodifyi...原创 2019-03-24 08:15:12 · 171 阅读 · 0 评论 -
Leetcode 31. Next Permutation
Implementnext 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 o...原创 2019-03-29 06:12:30 · 141 阅读 · 0 评论 -
Leetcode 32. Longest Valid Parentheses
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...原创 2019-04-08 12:30:55 · 116 阅读 · 0 评论 -
Leetcode 33. Search in Rotated Sorted Array
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 ...原创 2019-04-08 12:42:45 · 133 阅读 · 0 评论 -
Leetcode 152. Maximum Product Subarray
Given an integer arraynums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation:[2,3] h...原创 2019-03-29 11:47:16 · 131 阅读 · 0 评论 -
40. Combination Sum II
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Each number incandidatesmay...原创 2019-07-08 13:36:44 · 246 阅读 · 0 评论 -
39. Combination Sum
Given asetof candidate numbers (candidates)(without duplicates)and a target number (target), find all unique combinations incandidateswhere the candidate numbers sums totarget.Thesamerepeat...原创 2019-07-08 11:18:00 · 141 阅读 · 0 评论 -
45. 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.Your goal is to...原创 2019-07-13 06:31:40 · 273 阅读 · 1 评论 -
34. Find First and Last Position of Element in Sorted Array
Given an array of integersnumssorted in ascending order, find the starting and ending position of a giventargetvalue.Your algorithm's runtime complexity must be in the order ofO(logn).If the...原创 2019-06-30 06:08:06 · 129 阅读 · 0 评论 -
36. Valid Sudoku
Determine if a9x9 Sudoku boardis valid.Only the filled cells need to be validatedaccording to the following rules:Each rowmust contain thedigits1-9without repetition. Each column must conta...原创 2019-06-30 11:58:40 · 125 阅读 · 0 评论 -
Leetcode 28. Implement strStr()
ImplementstrStr().Return the index of the first occurrence of needle in haystack, or-1if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example...原创 2019-03-25 13:13:40 · 145 阅读 · 0 评论 -
Leetcode 27. Remove Element
Given an arraynumsand a valueval, remove all instances of that valuein-placeand return the new length.Do not allocate extra space for another array, you must do this bymodifying the input arra...原创 2019-03-25 12:15:56 · 157 阅读 · 0 评论 -
Leetcode 22. 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:[ "((()))", "(()())", "(())()", "()(())"...原创 2019-01-31 11:23:04 · 185 阅读 · 0 评论 -
Leetcode 9.Palindrome Number
class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ ''' if x<0: return False if x=...原创 2018-09-05 22:20:50 · 117 阅读 · 0 评论 -
Leetcode 10. Regular Expression Matching
class Solution(object): def isMatch(self, s, p): """ :type s: str :type p: str :rtype: bool """ if len(p)==0: return len(s)==0 ...原创 2018-09-16 05:00:34 · 132 阅读 · 0 评论 -
Leetcode 11.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 (i, 0). Find two...原创 2018-09-16 09:40:40 · 127 阅读 · 0 评论 -
给一个生成1到5随机数的函数,写一个函数生成1到7的随机数
题目描述和讲解参考https://blog.youkuaiyun.com/MDreamlove/article/details/48599107这里解释一下,rand5能够产生1-5的随机数,要写rand7产生1-7的随机数。注意这里都是需要从1开始,才能用下面的公式。首先,从rand7是肯定可以生成rand5的,当用rand7的时候,只要出现大于5的数就丢掉,而且经过证明这样生成的rand5是等概率...原创 2018-09-29 12:38:07 · 7812 阅读 · 0 评论 -
Leetcode 43: Multiply Strings 大数相乘算法
给定两个以字符串形式表示的非负整数num1和num2,返回num1和num2的乘积,它们的乘积也表示为字符串形式。示例2:输入: num1 = "123", num2 = "456"输出: "56088"class Solution(object): def multiply(self, num1, num2): """ :...原创 2018-11-11 14:31:04 · 394 阅读 · 0 评论 -
Leetcode 12 13: Integer to Roman, Roman to Integer
https://leetcode.com/problems/integer-to-roman/description/Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI ...原创 2018-12-04 09:41:21 · 122 阅读 · 0 评论 -
Leetcode 15:3Sum
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not cont...原创 2018-12-23 08:20:16 · 145 阅读 · 0 评论 -
Leetcode 16:3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...原创 2019-01-07 00:03:26 · 200 阅读 · 0 评论 -
Leetcode 17: Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is giv...原创 2019-01-07 13:14:51 · 197 阅读 · 0 评论 -
Leetcode 18: 4Sum
Leetcode上有2Sum,3Sum等问题,基本思路都是一样的,从3Sum开始,固定其他数,剩下两个数变成2Sum问题。2Sum问题在排序数组里用首尾两个游标遍历class Solution(object): def fourSum(self, nums, target): """ :type nums: List[int] :typ...原创 2019-01-31 01:02:45 · 265 阅读 · 0 评论 -
Leetcode 19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2019-01-31 10:30:31 · 141 阅读 · 0 评论 -
Leetcode 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-01-31 10:48:05 · 237 阅读 · 1 评论 -
Leetcode 21. 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.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2019-01-31 10:52:42 · 188 阅读 · 0 评论 -
41. First Missing Positive
Given an unsorted integer array, find the smallest missingpositive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Outpu...原创 2019-07-11 09:43:18 · 292 阅读 · 0 评论
分享