Array
文章平均质量分 62
NoooName
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[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 · 324 阅读 · 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 · 357 阅读 · 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 · 345 阅读 · 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 · 485 阅读 · 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 · 351 阅读 · 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 · 309 阅读 · 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 · 568 阅读 · 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 N A P L S I原创 2015-02-09 22:01:49 · 390 阅读 · 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 · 482 阅读 · 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 · 426 阅读 · 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 · 430 阅读 · 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 · 327 阅读 · 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 · 433 阅读 · 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 · 329 阅读 · 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 · 347 阅读 · 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 · 308 阅读 · 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 · 327 阅读 · 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 · 333 阅读 · 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 · 442 阅读 · 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 · 372 阅读 · 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 · 457 阅读 · 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 · 515 阅读 · 0 评论 -
[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 · 388 阅读 · 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 · 386 阅读 · 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 · 327 阅读 · 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 · 346 阅读 · 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 · 375 阅读 · 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 · 367 阅读 · 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 · 322 阅读 · 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 · 424 阅读 · 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 · 290 阅读 · 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 · 354 阅读 · 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 · 463 阅读 · 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 · 305 阅读 · 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 · 261 阅读 · 0 评论 -
[Leetcode]Remove Element
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 new length. 很原创 2014-12-16 23:04:08 · 291 阅读 · 0 评论 -
[Leetcode]3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2015-01-28 13:46:18 · 386 阅读 · 0 评论 -
[Leetcode]Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1",原创 2015-01-29 14:50:13 · 316 阅读 · 0 评论 -
[Leetcode]Valid Sudoku
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 '.'. A partially fille原创 2015-01-28 23:07:32 · 317 阅读 · 0 评论 -
[Leetcode]Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. 如果两个单词所包含的字符和数量都是一样的,只是顺序不同,那么就为anagrams~如果是判断两个单词是否为anagrams,有两种解法:一种是用第一个词建立h原创 2015-01-29 14:22:47 · 422 阅读 · 0 评论
分享