LeetCode
ExcitedZhang
这个作者很懒,什么都没留下…
展开
-
[Leetcode 58] Length of Last Word
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.Note: A word is defined...原创 2019-03-14 23:09:49 · 74 阅读 · 0 评论 -
[LeetCode 59] Spiral Matrix II
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.Example:[[ 1, 2, 3 ],[ 8, 9, 4 ],[ 7, 6, 5 ]]分析这个题目是中等难度,难点不在于算法的难度,而是能比较快的写出没有bug的解法。...原创 2019-03-15 00:10:06 · 60 阅读 · 0 评论 -
[Leetcode 14] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".Example 1:Input: ["flower","flow","flight"]Output...原创 2019-03-17 11:20:58 · 84 阅读 · 0 评论 -
[LeetCode 24] Swap Nodes in Pairs
Given alinked list, swap every two adjacent nodes and return its head.You maynotmodify the values in the list's nodes, only nodes itself may be changed.Example:Given 1->2->3->4,...原创 2019-03-18 23:00:07 · 110 阅读 · 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-18 23:52:03 · 76 阅读 · 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-25 23:07:34 · 72 阅读 · 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 23:23:13 · 99 阅读 · 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 23:33:49 · 76 阅读 · 0 评论 -
[LeetCode 37] Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Asudoku solution must satisfyall ofthe following rules:Each of the digits1-9must occur exactlyonce in each row. Each of t...原创 2019-04-10 23:41:21 · 105 阅读 · 0 评论 -
[LeetCode 38] Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211is read off as"one 1"or11.11is read of...原创 2019-04-11 23:53:17 · 61 阅读 · 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-04-08 23:39:25 · 60 阅读 · 0 评论 -
[LeetCode 767] Reorganize String
Given a stringS, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same.If possible, output any possible result. If not possible, return the...原创 2019-04-15 23:27:32 · 71 阅读 · 0 评论 -
[LeetCode 35] Search Insert Position
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 in the array....原创 2019-04-09 22:59:34 · 67 阅读 · 0 评论 -
[LeetCode 12] Integer to Roman
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-13 12:05:16 · 64 阅读 · 0 评论 -
[LeetCode 13] Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-04-13 12:26:16 · 82 阅读 · 0 评论 -
[LeetCode 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-04-13 16:50:33 · 92 阅读 · 0 评论 -
[LeetCode 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]...原创 2019-04-13 17:23:26 · 59 阅读 · 0 评论 -
[LeetCode 753] Cracking the Safe
There is a box protected by a password. The password isndigits, where each letter can be one of the firstkdigits0, 1, ..., k-1.You can keep inputting the password, the password will automatical...原创 2019-04-21 11:17:13 · 185 阅读 · 0 评论 -
[LeetCode 329] Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside o...原创 2019-04-21 12:24:31 · 97 阅读 · 0 评论 -
[LeetCode 417] Pacific Atlantic Water Flow
Given anm x nmatrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top edges of the matrix and the "Atlantic ocean" touch...原创 2019-04-21 17:27:43 · 178 阅读 · 0 评论 -
[LeetCode 279] Perfect Squares
Given a positive integern, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum ton.Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Examp...原创 2019-04-21 17:59:01 · 78 阅读 · 0 评论 -
[LeetCode 406] Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), wherehis the height of the person andkis the number of people in front of this ...原创 2019-04-21 18:26:26 · 59 阅读 · 0 评论 -
[LeetCode 284] Peeking Iterator
Given an Iterator class interface with methods:next()andhasNext(), design and implement a PeekingIterator that support thepeek()operation -- it essentially peek() at the element that will be retu...原创 2019-04-21 19:13:05 · 74 阅读 · 0 评论 -
[LeetCode 228] Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous range;4,...原创 2019-04-21 19:30:08 · 64 阅读 · 0 评论 -
[LeetCode 287] Find the Duplicate Number
Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi...原创 2019-04-16 23:11:55 · 56 阅读 · 0 评论 -
[LeetCode 43] Multiply Strings
Given two non-negative integersnum1andnum2represented as strings, return the product ofnum1andnum2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Exam...原创 2019-04-14 16:03:52 · 57 阅读 · 0 评论 -
[LeetCode 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-04-14 17:30:27 · 74 阅读 · 0 评论 -
[LeetCode 46] Permutations
Given a collection ofdistinctintegers, return all possible permutations.Example:Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]分析这一道题是一道比较常见的递...原创 2019-04-14 17:44:37 · 68 阅读 · 0 评论 -
[LeetCode 47] Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.Example:Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]]分析这道题目与[LeetCode 46]...原创 2019-04-14 17:55:38 · 62 阅读 · 0 评论 -
[LeetCode 51] N-Queens
Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Eac...原创 2019-04-14 18:58:05 · 69 阅读 · 0 评论 -
[LeetCode 388] Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner:The string"dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"represents:dir subdir1 subdir2 file.extThe direct...原创 2019-04-17 23:48:38 · 104 阅读 · 0 评论 -
[LeetCode 42] Trapping Rain Water
Givennnon-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.The above elevation map is represented by array...原创 2019-04-22 22:49:31 · 77 阅读 · 0 评论 -
[LeetCode 297] Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be...原创 2019-04-22 23:38:52 · 80 阅读 · 0 评论 -
[LeetCode 380] Insert Delete GetRandom O(1)
Design a data structure that supports all following operations inaverageO(1)time.insert(val): Inserts an item val to the set if not already present. remove(val): Removes an item val from the ...原创 2019-04-27 11:02:13 · 72 阅读 · 0 评论 -
[LeetCode 295] Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.For example,[2,3,4], the median ...原创 2019-04-27 11:30:14 · 117 阅读 · 0 评论 -
[LeetCode 401] Binary Watch
A binary watch has 4 LEDs on the top which represent thehours(0-11), and the 6 LEDs on the bottom represent theminutes(0-59).Each LED represents a zero or one, with the least significant bit on ...原创 2019-04-27 15:23:27 · 80 阅读 · 0 评论 -
[LeetCode 341] Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Input: [[1,1],...原创 2019-04-27 15:51:48 · 75 阅读 · 0 评论 -
[LeetCode 274] H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to thedefinition of h-index on Wikipedia: "A sc...原创 2019-04-27 16:12:23 · 101 阅读 · 0 评论 -
[LeetCode 318] Maximum Product of Word Lengths
Given a string arraywords, find the maximum value oflength(word[i]) * length(word[j])where the two words do not share common letters. You may assume that each word will contain only lower case lett...原创 2019-05-02 11:15:02 · 681 阅读 · 0 评论 -
[LeetCode 240] Search a 2D Matrix II
Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Integers in each...原创 2019-05-02 11:30:28 · 84 阅读 · 0 评论