![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数组
JohnWill_
小白一个,慢慢成长....
展开
-
Surrounded-regions 包围区域DFS
题目描述Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X X...原创 2018-03-23 10:18:49 · 168 阅读 · 0 评论 -
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 7might become4 5 6 7 0 1 2). You are given a target value to search. If found in the array return...原创 2018-04-03 19:30:28 · 83 阅读 · 0 评论 -
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 go...原创 2018-04-11 09:18:20 · 106 阅读 · 0 评论 -
Search in Rotated Sorted Array 2(有重复值)
题目描述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 t...原创 2018-04-03 20:28:38 · 93 阅读 · 0 评论 -
emove 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...原创 2018-04-03 21:08:37 · 191 阅读 · 0 评论 -
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,2,...原创 2018-04-03 22:07:42 · 69 阅读 · 0 评论 -
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 a...原创 2018-04-17 09:37:46 · 82 阅读 · 0 评论 -
Search for a Range 查找范围
题目描述Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not f...原创 2018-04-17 10:37:26 · 478 阅读 · 0 评论 -
subsets
题目描述Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For exa...原创 2018-04-04 15:00:37 · 129 阅读 · 0 评论 -
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 pos...原创 2018-04-17 16:20:39 · 178 阅读 · 0 评论 -
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 inte...原创 2018-04-05 13:33:47 · 62 阅读 · 0 评论 -
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...原创 2018-04-12 15:17:59 · 94 阅读 · 0 评论 -
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....原创 2018-04-18 10:46:22 · 466 阅读 · 0 评论 -
First Missing Positive
题目描述Given an unsorted integer array, find the first missing positive integer. For example, Given[1,2,0]return3, and[3,4,-1,1]return2. Your algorithm should run in O(n) time and uses constant spa...原创 2018-04-12 16:58:04 · 75 阅读 · 0 评论 -
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...原创 2018-04-23 14:28:55 · 107 阅读 · 0 评论 -
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,...原创 2018-04-23 20:49:23 · 204 阅读 · 0 评论 -
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 ...原创 2018-04-23 21:35:43 · 212 阅读 · 0 评论 -
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: Eleme...原创 2018-04-23 22:31:27 · 99 阅读 · 0 评论 -
combination sumII
题目描述Given a collection of candidate numbers ( C ) and a target number ( T ), find all unique combinations in C where the candidate numbers sums to T . Each number in C may only b...原创 2018-04-16 14:18:55 · 140 阅读 · 0 评论 -
Combination Sum
题目描述Given a set of candidate numbers ( C ) and a target number ( T ), find all unique combinations in C where the candidate numbers sums to T . The same repeated number may be chose...原创 2018-04-16 10:11:51 · 90 阅读 · 0 评论 -
数组最大连续长度
题目描述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]. ...原创 2018-03-23 16:17:35 · 1984 阅读 · 0 评论 -
subset2求数组子集
题目描述Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contai...原创 2018-03-30 14:32:19 · 196 阅读 · 0 评论 -
Plus One
题目描述Given a number represented as an array of digits, plus one to the number. 将一个数字的每个位上的数字分别存到一个一维向量中,最高位在最开头,我们需要给这个数字加一,即在末尾数字加一,如果末尾数字是9,那么则会有进位问题,而如果前面位上的数字仍为9,则需要继续向前进位。具体算法如下:首先判断最后一位是否为9,若不是,...原创 2018-04-07 16:50:44 · 106 阅读 · 0 评论 -
Best Time to Buy and Sell Stock I
题目描述Say you have an array for which the i th element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the ...原创 2018-03-25 21:19:57 · 158 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
题目描述Say you have an array for which the i th 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,...原创 2018-03-25 21:49:05 · 88 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
题目描述Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note: Yo...原创 2018-03-25 22:30:35 · 112 阅读 · 0 评论 -
grey 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 sequenc...原创 2018-03-31 22:32:07 · 1055 阅读 · 0 评论 -
数组Single Number 1
题目:Given an array of integers, every element appears twiceexcept for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra ...原创 2018-03-21 22:23:08 · 136 阅读 · 0 评论 -
数组Single Number 2
题目:Given an array of integers, every element appears threetimes except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ...原创 2018-03-22 09:50:09 · 106 阅读 · 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 to hold additional elements from B. The number of elements initialize...原创 2018-04-01 21:39:09 · 149 阅读 · 0 评论 -
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 ]] ...原创 2018-04-09 14:23:03 · 603 阅读 · 0 评论 -
Spiral Matrix II (螺旋写入矩阵)
题目描述Given an integer n, generate a square matrix filled with elements from 1 to n 2 in spiral order. For example, Given n =3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ]...原创 2018-04-09 14:59:52 · 185 阅读 · 0 评论 -
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....原创 2018-04-09 19:19:19 · 140 阅读 · 0 评论 -
区间合并问题 Merge Interval
题目描述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]. 思路:我们首先要做的就是给区间集排序,由于我们要排序的是个结构体,所以我们要定义自己的comparator...原创 2018-04-09 20:53:29 · 853 阅读 · 0 评论 -
jump-game
题目描述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. Determi...原创 2018-04-09 21:40:02 · 76 阅读 · 0 评论 -
Maximum Subarray
题目描述Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array[−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray[4,−1,2,1]h...原创 2018-04-09 22:50:50 · 84 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
题目描述Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 和有序链表化为BST方法一样,递归求解;注:中间必须要两个中间结点的后一个!!!实现代码: * Definition for binary tree * struct TreeNode { * ...原创 2018-03-27 21:25:32 · 109 阅读 · 0 评论 -
Median of Two Sorted Arrays求中位数
题目描述There are two sorted arrays A and B 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)). 解题思路:将两个有序数组合并为一个,设置一个 map<...原创 2018-04-19 20:01:19 · 85 阅读 · 0 评论