leetcode数组
葱shen
爱技术,爱学习,爱游戏~
展开
-
[leetcode] 【数组】48. 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?题意用二维数组表示一张2d图片,将图片顺时针旋转90°,不使用额外空间。题解1、由外往内一原创 2016-05-25 13:37:02 · 239 阅读 · 0 评论 -
[leetcode] 【数组】1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution. Example: Given nums = [2, 7, 1原创 2016-05-22 02:16:51 · 246 阅读 · 0 评论 -
[leetcode] 【数组】128. 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, 4].原创 2016-05-22 02:03:47 · 375 阅读 · 0 评论 -
[leetcode] 【数组】4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).题解这是一道非常经典的题。这题更通用的形式是,给定两个已经排原创 2016-05-22 01:44:38 · 308 阅读 · 0 评论 -
[leetcode]【数组】81. 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 array.题解原创 2016-05-22 00:07:59 · 265 阅读 · 0 评论 -
[leetcode]【数组】33. 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 return its index原创 2016-05-22 00:00:10 · 278 阅读 · 0 评论 -
[leetcode]【数组】80. Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elemen原创 2016-05-21 23:47:02 · 325 阅读 · 0 评论 -
[leetcode] 第一类--【数组】 题大纲
第一类关于数组的题都写完了,大多数都还是比较经典的题。在学习的路上,大家一起努力~60. Permutation Sequence 36. Valid Sudoku42. Trapping Rain Water48. Rotate Image26. Remove Duplicates from Sorted Array80. Remove Duplicat原创 2016-05-30 10:56:47 · 353 阅读 · 0 评论 -
[leetcode] 【数组】 60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):“123” “132” “213” “231” “312”原创 2016-05-22 19:47:04 · 281 阅读 · 0 评论 -
[leetcode] 【数组】36. 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 filled sudoku whic原创 2016-05-22 20:04:55 · 284 阅读 · 0 评论 -
[leetcode] 【数组】42. 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], ret原创 2016-05-22 22:14:28 · 347 阅读 · 0 评论 -
[leetcode] 【数组】15. 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) must be i原创 2016-05-22 02:26:05 · 228 阅读 · 0 评论 -
[leetcode] 【数组】16. 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 exactly原创 2016-05-22 02:29:01 · 238 阅读 · 0 评论 -
[leetcode] 【数组】18. 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: Elements in a quad原创 2016-05-22 02:44:57 · 525 阅读 · 0 评论 -
[leetcode] 【数组】 66. 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.题意用一个数组表示一个数,每原创 2016-05-25 14:09:03 · 233 阅读 · 0 评论 -
[leetcode] 【数组】70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?题意 爬一个n阶楼梯,每次可以爬1-2步,问有多少种原创 2016-05-25 14:37:04 · 257 阅读 · 0 评论 -
[leetcode] 【数组】 89. Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2016-05-28 10:59:36 · 294 阅读 · 0 评论 -
[leetcode] 【数组】73. 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.题意给定一个二维数组表示一个矩阵,如果某个元素为0,那么把这个元素所在行和列的所有元素置为0。不使用额外空间。题解使用额外的空间的话,就是做两个一维数组,分别标记哪一行哪一列有0,然后把这些行和原创 2016-05-28 11:42:42 · 1505 阅读 · 0 评论 -
[leetcode] 【数组】134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2016-05-29 23:06:40 · 283 阅读 · 0 评论 -
[leetcode] 【数组】 135. Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2016-05-29 23:23:09 · 444 阅读 · 0 评论 -
[leetcode] 【数组】 136. 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原创 2016-05-30 10:21:59 · 234 阅读 · 0 评论 -
[leetcode] 【数组】 137. 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原创 2016-05-30 10:32:18 · 269 阅读 · 0 评论 -
[leetcode] 【数组】31. 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 orde原创 2016-05-22 12:28:02 · 256 阅读 · 0 评论 -
[leetcode] 【数组】27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order原创 2016-05-22 03:01:11 · 218 阅读 · 0 评论 -
[leetcode]【数组】26. 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 cons原创 2016-05-21 23:37:13 · 276 阅读 · 0 评论