![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode(c++)
文章平均质量分 62
LandscapeMi
这个作者很懒,什么都没留下…
展开
-
leetcode_c++:Rotate Image(048)
题目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?算法复杂度:O(n^2)对角线swap行反转class Solution {public: void rot原创 2016-05-23 23:02:40 · 308 阅读 · 0 评论 -
leetcode_c++:4sum(016)
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 q原创 2016-05-11 14:33:36 · 328 阅读 · 0 评论 -
leetcode_c++:Remove Duplicates from Sorted Array(026)
题目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 c原创 2016-05-11 23:39:42 · 220 阅读 · 0 评论 -
leetcode_c++:Remove Element (027)
题目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 ord原创 2016-05-13 00:08:40 · 196 阅读 · 0 评论 -
leetcode_c++:Next Permutation (031)
题目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 or原创 2016-05-13 00:54:27 · 398 阅读 · 0 评论 -
leetcode_c++:Spiral Matrix(054)
题目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 ] ] You原创 2016-05-31 00:15:37 · 247 阅读 · 0 评论 -
leetcode_c++:Maximum Subarray(053)
题目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] has t原创 2016-05-24 00:52:24 · 424 阅读 · 0 评论 -
leetcode_c++: Jump Game(055)
题目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.Determine i原创 2016-05-31 01:21:12 · 458 阅读 · 0 评论 -
leetcode_c++:Search in Rotated Sorted Array(033)
题目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 ind原创 2016-05-17 22:59:43 · 238 阅读 · 0 评论 -
leetcode_c++:Search for a Range(034)
题目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 found in the原创 2016-05-18 00:45:22 · 576 阅读 · 0 评论 -
leetcode_c++:Search insert position(035)
题目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.Her原创 2016-05-18 01:09:38 · 211 阅读 · 0 评论 -
leetcode_c++:Median_of _two_sorted_arrays(004)
题目两个已经排序好的数组num1和num2,长度分别是m和n。找到两个有序数组的中位数(中间的那个数,若为偶数,则是中间的两个数的平均数)要求复杂度是O(lg(n+m))算法1 Merge两个数组,然后取得中位数复杂度:O(n+m)#include <iostream>#include <algorithm>#include <vector>using namespace std;con原创 2016-05-06 00:56:08 · 277 阅读 · 0 评论 -
leetcodec_c++:Container With Most Water(011)
题目: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 two原创 2016-05-08 13:32:22 · 271 阅读 · 0 评论 -
leetcode_c++:Merge_Intervals(056)
题目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].算法复杂度:O(nm)#include<iostream>#include<vector>#include <原创 2016-05-31 22:44:28 · 610 阅读 · 0 评论 -
leetcode_c++:Insert Intervals(057)
题目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.Example原创 2016-05-31 22:52:58 · 217 阅读 · 0 评论 -
leetcode_c++: Spiral Matrix II(059)
题目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 ], [ 7原创 2016-06-01 00:28:33 · 290 阅读 · 0 评论 -
leetcode_c++: Unique Paths(062)
题目A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bot原创 2016-06-01 00:50:50 · 219 阅读 · 0 评论 -
leetcode_c++:Unique Paths II(063)
题目Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the gr原创 2016-06-01 22:44:32 · 233 阅读 · 0 评论 -
leetcode_c++:Minimum Path Sum (064)
题目Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at an原创 2016-06-01 23:52:05 · 203 阅读 · 0 评论 -
Leetcode_c++:Plus one(066)
题目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.//给一个用数组表示的数,加1后还是数组表示算法复杂度原创 2016-06-02 00:24:46 · 193 阅读 · 0 评论 -
Leetcode_c++:Set Matrix Zeros (073)
题目Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.算法复杂度:O(n+m)先通过两个数组来记录该行该列上有没有零元素,等对矩阵遍历完之后再统一修改即可。1)创建一个两个数组,分别用于记录矩阵中的行和列是否需要变为0的标志; 2)遍历矩阵,标记矩阵中哪些行和哪些原创 2016-06-02 00:37:39 · 419 阅读 · 0 评论 -
leetcode_c++:3Sum(015)
题目 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) m原创 2016-05-09 21:35:25 · 1722 阅读 · 0 评论 -
leetcode_c++:3Sum Closest(016)
题目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 exactl原创 2016-05-09 22:07:44 · 290 阅读 · 0 评论 -
leetcode_c++:2Sum (001)
123原创 2016-05-10 02:09:14 · 246 阅读 · 0 评论 -
Leetcode_c++: Largest Rectangle in Histogram (084)
题目Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each ba原创 2016-06-07 22:12:38 · 262 阅读 · 0 评论 -
Leetcode_c++: Maximal Rectangle (085)
题目Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.算法http://www.cnblogs.com/felixfang/p/3676193.html有了上一题的基础,这道题就可等效为上一题,对于矩阵每一行,我们将其原创 2016-06-07 23:01:01 · 305 阅读 · 0 评论 -
Leetcode_c++: Merge Sorted Array (088)
题目Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addition原创 2016-06-07 23:09:46 · 209 阅读 · 0 评论 -
Leetcode_c++: Subsets II (090)
题目Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,2], a solution i原创 2016-06-07 23:15:57 · 292 阅读 · 0 评论 -
Leetcode_c++:Construct Binary Tree from Preorder and Inorder Traversal(105)
题目Given preorder and inorder traversal of a tree, construct the binary tree.算法从前序中序遍历来重构二叉树O(n) 这种题一般有二种形式,共同点是都已知中序序列。如果没有中序序列,是无法唯一确定一棵树的。 <1>已知二叉树的前序序列和中序序列,求解树。 1、确定树的根节点。树根是当前树中所有元素在前序遍历中最先出现的元原创 2016-06-07 23:37:36 · 561 阅读 · 0 评论 -
Leetcode_c++: Search a 2D Matrix (074)
题目Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first integer of each row原创 2016-06-03 00:35:21 · 316 阅读 · 0 评论 -
Leetcode_c++: Sort Colors (075)
题目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 0,原创 2016-06-03 00:48:30 · 253 阅读 · 0 评论 -
leetcode_c++:Find the Duplicate Number(287)
题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, f原创 2016-06-24 13:26:01 · 289 阅读 · 0 评论 -
leetcode_c++:Game of Life(289)
题目According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a board with m by n原创 2016-06-24 14:49:15 · 347 阅读 · 0 评论 -
leetcode_c++:哈希:Longest Substring Without Repeating Characters(003)
题目Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the原创 2016-06-25 13:39:53 · 221 阅读 · 0 评论 -
leetcode_c++:Combination Sum(039)
题目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 chosen from C unlimited numb原创 2016-05-22 23:55:06 · 528 阅读 · 0 评论 -
leetcode_c++:Combination Sum_2(040)
题目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 be used once in the combination.原创 2016-05-23 00:08:02 · 380 阅读 · 0 评论 -
leetcode_c++:First Missing Positive(041)
题目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 space.原创 2016-05-23 00:28:48 · 327 阅读 · 0 评论 -
leetcode_c++:trappint rain water(042)
题目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], r原创 2016-05-23 01:21:45 · 237 阅读 · 0 评论 -
leetcode_c++:哈希:Substring with Concatenation of All Words(030)
题目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) in s that is a concatenation of each word in words exactly once and w原创 2016-06-26 14:35:34 · 209 阅读 · 0 评论 -
Leetcode_c++:Construct Binary Tree from Inorder and Postorder Traversal (106)
题目Given inorder and postorder traversal of a tree, construct the binary tree.算法O(N)#include<iostream>#include<vector>#include<stack>#include <algorithm>using namespace std;const int N=0;//Definitio原创 2016-06-10 22:18:28 · 280 阅读 · 0 评论