![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LEETCODE
文章平均质量分 60
停止更新+1
养兵千日用兵一时,磨刀不误砍柴工。
展开
-
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原创 2014-12-16 09:54:02 · 309 阅读 · 0 评论 -
LEETCODE: 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 found原创 2014-12-16 10:09:20 · 186 阅读 · 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.原创 2014-12-16 10:25:19 · 204 阅读 · 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原创 2014-12-16 13:57:45 · 286 阅读 · 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原创 2014-12-15 17:22:26 · 245 阅读 · 0 评论 -
LEETCODE: 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 chosen from C unlimited numb原创 2014-12-16 18:08:57 · 200 阅读 · 0 评论 -
LEETCODE: Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.这题不难,就是觉得麻烦。下面是按照人类自己笔算乘法的方式写的。原创 2014-12-17 22:14:04 · 222 阅读 · 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]原创 2014-12-17 12:11:02 · 306 阅读 · 0 评论 -
LEETCODE: 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原创 2015-01-06 22:25:36 · 307 阅读 · 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 usi原创 2015-01-06 23:02:17 · 303 阅读 · 0 评论 -
LEETCODE: Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2014-12-16 17:15:53 · 274 阅读 · 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原创 2014-12-16 17:42:03 · 246 阅读 · 0 评论 -
LEEDCODE: Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2015-01-06 22:16:52 · 370 阅读 · 0 评论 -
LEETCODE: Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2015-01-06 15:38:49 · 263 阅读 · 0 评论 -
LEETCODE: 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原创 2015-01-06 22:33:33 · 323 阅读 · 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-06 22:39:27 · 266 阅读 · 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原创 2014-12-17 10:03:20 · 195 阅读 · 0 评论 -
LEETCODE: Combination Sum II
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 combina原创 2014-12-16 20:48:00 · 202 阅读 · 0 评论 -
LEETCODE: Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-12-18 15:39:52 · 249 阅读 · 0 评论 -
LEETCODE: 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)). 看到这个问题,最初觉得很容易。做起来其实不然,为什么呢?这个问题原创 2014-12-02 22:24:49 · 282 阅读 · 0 评论 -
LEETCODE: 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 goal i原创 2014-12-18 17:25:34 · 321 阅读 · 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. For原创 2014-12-03 18:16:29 · 265 阅读 · 0 评论 -
LEETCODE: Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].原来想用next permut原创 2014-12-18 20:54:56 · 248 阅读 · 0 评论 -
LEETCODE: Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-12-18 22:20:55 · 223 阅读 · 0 评论 -
LEETCODE: 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] ha原创 2014-12-19 22:02:58 · 198 阅读 · 0 评论 -
LEETCODE: 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""3原创 2014-12-20 22:19:52 · 238 阅读 · 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,英文的回文,只要组成这些单词用的字母个数和类型相同就是回文。class Solution {public:原创 2014-12-19 18:12:00 · 265 阅读 · 0 评论 -
LEETCODE: N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-12-19 18:55:32 · 183 阅读 · 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?class Solution {public: void rotate(vector原创 2014-12-19 11:31:00 · 286 阅读 · 0 评论 -
LEETCODE: 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.Determine i原创 2014-12-19 23:17:45 · 210 阅读 · 0 评论 -
LEETCODE: Unique Paths
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原创 2014-12-21 11:14:11 · 234 阅读 · 0 评论 -
LEETCODE: Pow(x, n)
Implement pow(x, n).用递归吧,虽然我尝试了用非递归,但是没有成功。class Solution {public: double powinternal(double x, int n) { if(n == 0) return 1; double half = powinternal(x, n / 2原创 2014-12-19 18:26:30 · 300 阅读 · 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原创 2014-12-20 12:08:39 · 266 阅读 · 0 评论 -
LEETCODE: Add Two Number
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-12-04 09:43:48 · 548 阅读 · 0 评论 -
LEETCODE: Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut原创 2015-01-10 14:08:59 · 294 阅读 · 0 评论 -
LEETCODE: N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.把上题稍微改了一下。似乎这个没有考虑对称的问题,那就无所谓了。class Solution {public:原创 2014-12-19 19:02:09 · 218 阅读 · 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 ]]原创 2014-12-19 22:50:05 · 258 阅读 · 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 ], [原创 2014-12-20 18:34:19 · 172 阅读 · 0 评论 -
LEETCODE: Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./** * Definition for sing原创 2015-01-09 21:36:00 · 280 阅读 · 0 评论 -
LEETCODE: Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2015-01-09 22:33:26 · 315 阅读 · 0 评论