![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
政教处挨批
这个作者很懒,什么都没留下…
展开
-
Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 andn (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numbe原创 2015-11-17 21:13:03 · 1197 阅读 · 1 评论 -
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?题意:原创 2014-10-05 12:21:16 · 413 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100".题意:将两个代表二进制原创 2014-10-05 12:17:27 · 978 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-10-05 12:13:07 · 464 阅读 · 0 评论 -
Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ],原创 2014-10-05 11:57:34 · 427 阅读 · 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 exam原创 2014-10-05 12:37:41 · 528 阅读 · 0 评论 -
Combinations
Given two integers n and k, return all possible combinations ofk numbers out of 1 ... n. For example,If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [原创 2014-10-05 12:34:11 · 539 阅读 · 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 integers原创 2014-10-05 12:32:05 · 437 阅读 · 0 评论 -
Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.题意:合并两个已经排序号的原创 2014-10-05 12:15:57 · 504 阅读 · 0 评论 -
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 bo原创 2014-10-05 12:09:04 · 443 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL andk = 2,return 4->5->1->2->3->NULL.题意:将链表原创 2014-10-05 12:03:50 · 395 阅读 · 0 评论 -
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 defi原创 2014-10-05 11:55:09 · 404 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce. For example,Given 1->1->2, return1->2.Given 1->1->2->3->3, return1->2->3.代码:链表类的问题原创 2014-09-25 20:44:50 · 400 阅读 · 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.Examp原创 2014-09-25 20:41:26 · 388 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinct numbers from the original list. For example,Given 1->2->3->3->4->4->5, return1->2->5.Given 1->1原创 2014-09-25 20:46:24 · 391 阅读 · 0 评论 -
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.题意:有一个m*n的二维数组,原创 2014-10-05 12:26:21 · 518 阅读 · 0 评论 -
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原创 2014-10-29 21:24:47 · 455 阅读 · 0 评论 -
Unique Paths II
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 and0 respectively in the grid.原创 2014-10-05 12:10:47 · 480 阅读 · 0 评论 -
Missing Number
从一组非负整数中找出缺少的数,比如[0,1,3],缺少2原创 2015-11-15 13:47:26 · 868 阅读 · 0 评论 -
Basic Calculator
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2015-11-13 23:16:16 · 443 阅读 · 0 评论 -
Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in原创 2015-11-06 22:32:05 · 435 阅读 · 0 评论 -
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-11-04 18:03:28 · 757 阅读 · 0 评论 -
Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in st原创 2015-10-29 22:28:48 · 505 阅读 · 0 评论 -
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-04-16 17:19:55 · 365 阅读 · 0 评论 -
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].解法:用栈来做,先将父节点入栈,再将右孩子原创 2015-04-16 17:14:59 · 497 阅读 · 0 评论 -
Regular Expression Matching
'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(c原创 2015-04-16 17:05:06 · 429 阅读 · 0 评论 -
Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.题意:找出一组字符串中是满足回文构词法(字符串中字符相同,但是顺序不同)的字符串数组。思路:对字符串数组中的每个字符串按字符排序,通过得到的字符序列来判断原创 2015-04-16 16:58:14 · 430 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the fol原创 2015-04-18 09:07:50 · 416 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n).注意:n可能小于0错误:pow(x,n) = x * pow(x,n - 1)栈溢出代码:public class Solution { public double pow(double x, int n) { if(n == 0) return 1; if(n < 0)原创 2015-04-18 19:47:13 · 543 阅读 · 0 评论 -
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-04-01 13:35:52 · 363 阅读 · 0 评论 -
Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 0000原创 2015-03-12 10:21:12 · 343 阅读 · 0 评论 -
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.题意:将一个用原创 2014-10-05 12:19:49 · 428 阅读 · 0 评论 -
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].解法一:原创 2014-09-25 20:40:10 · 374 阅读 · 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] ha原创 2014-09-25 20:37:14 · 364 阅读 · 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 7 might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its原创 2014-09-14 20:57:40 · 384 阅读 · 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)).s原创 2014-08-12 19:09:30 · 314 阅读 · 0 评论 -
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-08-13 12:42:42 · 361 阅读 · 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,1]原创 2014-09-20 09:42:53 · 466 阅读 · 0 评论 -
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-09-20 09:40:24 · 363 阅读 · 0 评论 -
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-09-20 09:31:07 · 374 阅读 · 0 评论