![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Array
文章平均质量分 62
NoooName
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E原创 2015-03-12 06:56:24 · 323 阅读 · 0 评论 -
[Leetcode]Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-01-22 22:43:56 · 377 阅读 · 0 评论 -
[Leetcode]Plus One
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.对一个数组进行加一操作~ 维护一个进位原创 2015-01-04 22:27:20 · 438 阅读 · 0 评论 -
[Leetcode]ZigZag Conversion
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 legibility)P A H NA P L S I原创 2015-02-09 22:01:49 · 342 阅读 · 0 评论 -
[Leetcode]Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Clarification:What constitutes a word?A sequence of non-spac原创 2015-02-08 22:46:40 · 496 阅读 · 0 评论 -
[Leetcode]Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updat原创 2015-02-08 15:58:47 · 235 阅读 · 0 评论 -
[Leetcode]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原创 2015-02-05 13:46:47 · 296 阅读 · 0 评论 -
[Leetcode]Longest Palindromic Substring
Given 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 palindromic substring.求最大长度的回文子串~比较直接的方法原创 2015-02-03 17:22:55 · 419 阅读 · 0 评论 -
[Leetcode]Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2015-02-04 16:40:11 · 299 阅读 · 0 评论 -
[Leetcode]Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3原创 2015-01-13 22:29:28 · 304 阅读 · 0 评论 -
[Leetcode]First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant原创 2015-02-10 22:21:12 · 366 阅读 · 0 评论 -
[Leetcode]Best Time to Buy and Sell Stock II
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 like (ie, buy on原创 2015-01-22 22:16:01 · 280 阅读 · 0 评论 -
[Leetcode]Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2015-01-22 23:09:03 · 261 阅读 · 0 评论 -
[Leetcode]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原创 2015-03-11 02:56:05 · 441 阅读 · 0 评论 -
[Leetcode]Merge Intervals
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].要求合并若干个区间~记得先把intervals按start值排序~# Definitio原创 2015-03-11 06:21:52 · 393 阅读 · 0 评论 -
[Leetcode]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-01-29 11:32:31 · 319 阅读 · 0 评论 -
[Leetcode]Majority Element
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 majority element原创 2015-03-26 01:13:27 · 378 阅读 · 0 评论 -
[Leetcode]Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?Pascal's原创 2015-01-05 22:15:43 · 273 阅读 · 0 评论 -
[Leetcode]Pascal's Triangle
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]]给定行数n,让你返回Pascal's原创 2015-01-05 21:45:21 · 277 阅读 · 0 评论 -
[Leetcode]Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements fro原创 2015-01-04 22:59:06 · 264 阅读 · 0 评论 -
[Leetcode]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.原创 2015-01-06 10:39:21 · 297 阅读 · 0 评论 -
[Leetcode]Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2015-01-22 22:36:05 · 279 阅读 · 0 评论 -
[Leetcode]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.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad i原创 2015-01-14 13:37:31 · 382 阅读 · 0 评论 -
[Leetcode]Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2015-01-13 22:04:09 · 255 阅读 · 0 评论 -
[Leetcode]3Sum
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:Elements in a triplet (a,b,c原创 2015-01-28 11:03:45 · 387 阅读 · 0 评论 -
[Leetcode]Find Minimum 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).Find the minimum element.You may assume no duplicate exists in原创 2015-01-07 15:38:28 · 297 阅读 · 0 评论 -
[Leetcode]Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,原创 2015-01-06 22:24:00 · 247 阅读 · 0 评论 -
[Leetcode]Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Find Minimum in Rotated Sorted Array的扩展题,这题中有重复元素的出原创 2015-01-07 22:31:15 · 373 阅读 · 0 评论 -
[Leetcode]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 array retur原创 2015-01-07 12:20:02 · 271 阅读 · 0 评论 -
[Leetcode]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,1,3,2,1,2,1]原创 2015-01-27 16:29:19 · 307 阅读 · 0 评论 -
[Leetcode]Sort Colors
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 the integers原创 2015-01-06 11:25:36 · 330 阅读 · 0 评论 -
[Leetcode]Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the原创 2015-01-07 14:45:21 · 297 阅读 · 0 评论 -
[Leetcode]Remove Duplicates from Sorted Array
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 in place with原创 2014-12-16 23:32:07 · 283 阅读 · 0 评论 -
[Leetcode]Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?90度旋转图片~基本思路是把图片分为n/2层,然后一层层进行旋转,每一层有上下左右四个列,然后就是把上原创 2015-01-08 23:19:26 · 257 阅读 · 0 评论 -
[Leetcode]Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2015-01-08 23:55:28 · 208 阅读 · 0 评论 -
[Leetcode]4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2015-01-28 16:09:27 · 331 阅读 · 0 评论 -
[Leetcode]Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.求所有的字符串的最长公共前缀~直接用brute force的解法~class Solution: # @return a string def longestCommonPrefix(self,原创 2015-02-02 23:12:22 · 419 阅读 · 0 评论 -
[Leetcode]Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2015-01-12 22:30:08 · 409 阅读 · 0 评论 -
[Leetcode]Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]原创 2015-01-13 19:31:04 · 266 阅读 · 0 评论 -
[Leetcode]Two Sum
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 the target, whe原创 2015-01-13 17:22:45 · 338 阅读 · 0 评论