![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode刷题笔记
LittleBob180
if(仰望星空&&脚踏实地) return bonus;
展开
-
Unique Binary Search Trees题解
题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2015-01-15 14:17:48 · 408 阅读 · 0 评论 -
ump Game II_Leetcode_#45
1 题目 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 is t原创 2016-09-13 11:42:31 · 409 阅读 · 0 评论 -
Wildcard Matching_Leetcode_#44
1 题目 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原创 2016-09-13 11:37:28 · 291 阅读 · 0 评论 -
Trapping Rain Water_Leetcode_#42
1 题目 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原创 2016-09-13 11:29:07 · 249 阅读 · 0 评论 -
First Missing Positive_Leetcode_#41
1 题目 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 sp原创 2016-09-13 11:24:23 · 225 阅读 · 0 评论 -
Combination Sum_Leetcode_#39
1 题目 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 numbe原创 2016-09-10 20:06:39 · 238 阅读 · 0 评论 -
Combination Sum II_Leetcode_#40
1 题目 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 combinat原创 2016-09-10 20:07:53 · 193 阅读 · 0 评论 -
Valid Sudoku_Leetcode_#36
1 题目 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 ‘.’.Note: A valid Sudoku boar原创 2016-09-10 19:59:50 · 241 阅读 · 0 评论 -
Soduku Solver_Leetcode_37
1 题目 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.2 解法public class Solu原创 2016-09-10 20:02:56 · 348 阅读 · 0 评论 -
Search Insert Position_Leetcode_35
1 题目 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原创 2016-09-10 19:55:56 · 223 阅读 · 0 评论 -
Search for a range_Leetcode_#34
1 题目 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原创 2016-09-10 19:53:02 · 174 阅读 · 0 评论 -
Search in Rotated Sorted Array_Leetcode_#33
1 题目 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原创 2016-09-10 19:48:48 · 191 阅读 · 0 评论 -
Longest Valid Parentheses_Leetcode_#32
1 题目 Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, whi原创 2016-09-10 19:47:08 · 249 阅读 · 0 评论 -
Next Permutation_Leetcode_#31
1.题目 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 possibl原创 2016-09-10 19:44:04 · 191 阅读 · 0 评论 -
Permutations_Leetcode_#46
1 题目 Given a collection of distinct 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], [原创 2016-09-13 11:57:30 · 248 阅读 · 0 评论 -
Longest Palindromic Substring_Leetcode_#5
1.题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.2.解法 思路:从数组开始处作为起点,并原创 2016-08-13 09:56:17 · 240 阅读 · 0 评论 -
Zigzag Conversion_Leetcode_#6
1.题目 The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S原创 2016-08-13 10:05:43 · 243 阅读 · 0 评论 -
Longest Substring Without Repeating Characters_leetcode_#3
1.题目 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原创 2016-08-08 23:25:24 · 172 阅读 · 0 评论 -
Median of Two Sorted Arrays_leetcode_#4
1.题目 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)).Example 1: nums1 = [1, 3原创 2016-08-09 22:17:17 · 259 阅读 · 0 评论 -
3Sum Closest_Leetcode_#16
1.题目 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 ex原创 2016-08-14 11:45:24 · 194 阅读 · 0 评论 -
Valid Parentheses_Leetcode_#20
1.题目 Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid原创 2016-08-14 18:55:59 · 270 阅读 · 0 评论 -
Remove Nth Node From End of List_Leetcode_#19
1.题目 Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked l原创 2016-08-14 17:19:59 · 194 阅读 · 0 评论 -
4Sum_Leetcode_#18
1.题目 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: The solution原创 2016-08-14 16:36:42 · 187 阅读 · 0 评论 -
3Sum_Leetcode_#15
1.题目 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: The solution set must not contain原创 2016-08-14 10:59:06 · 162 阅读 · 0 评论 -
Longest common prefix_Leetcode_#14
1.题目 Write a function to find the longest common prefix string amongst an array of strings.2.解法 思路:先求得字符串数组中的最小长度minLen,最大的公共前部的长度为minLen,最多遍历字符串数组MinLen次即可。 遍历一次,中间遇到有不相同的就立即返回结果。public class Solut原创 2016-08-13 20:48:52 · 154 阅读 · 0 评论 -
Integer to Roman_Leetcode_#12
题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.我的解法:(1)算法思想:罗马数字的组合规则见上一篇blog《Roman to Integer题解》。(2)代码如下:{CSDN:原创 2015-01-17 17:04:09 · 335 阅读 · 0 评论 -
Container with most water_Leetcode_#11
1.题目 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 t原创 2016-08-13 19:58:52 · 249 阅读 · 0 评论 -
String to Integer_Leetcode_#8
1.题目 Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input c原创 2016-08-13 16:08:04 · 184 阅读 · 0 评论 -
Palindrome Number_Leetcode_#9
1.题目 Determine whether an integer is a palindrome. Do this without extra space.2.解法 思路:类似于翻转一个数,定义一个y,从个位开始,取该位的数字,y = y*10 + x1%10。最后比较y与x是否相等。 时间复杂度:O(N) public class Solution { public boo原创 2016-08-13 16:03:37 · 194 阅读 · 0 评论 -
Reverse digits of an integer_Leetcode_#7
1.题目 Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321 2.解法 思路:考虑溢出的情况 时间复杂度O(N)public class Solution { public int reverse(int x){ boolean bPos原创 2016-08-13 10:09:10 · 271 阅读 · 0 评论 -
Divide Two Integers_Leetcode_#29
1 题目 Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.2 解法public class Solution { public int divide(int dividend, int divisor) {原创 2016-08-18 21:43:00 · 210 阅读 · 0 评论 -
Implement strStr()_Leetcode_#28
1 题目 Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.2 解法public class Solution { public int strStr(String haystack, St原创 2016-08-18 21:41:58 · 194 阅读 · 0 评论 -
Two Sum_leetcode_#1
0.题记 Bob今天开始要强势回归Leetcode刷题啦撒花撒花LOL。 作为一名即将研二的学生党,正式开始了实习狗的生涯,平时加班不多,正是刷题解闷的大好机会啊O(∩_∩)O哈哈~ 给自己定个刷题计划吧: 第一阶段(2个月):从今天8月6号开始到10月6号,按照leetcode上面题目顺序从第1题开始刷,完成100题,每题刷完都写到CSDN博客上面。原创 2016-08-06 16:50:00 · 212 阅读 · 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 t原创 2015-01-17 16:45:44 · 332 阅读 · 0 评论 -
Remove Duplicates from Sorted List
题目 :Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.我的解法:(1)算法思想:原创 2015-01-17 17:17:32 · 726 阅读 · 0 评论 -
Same Tree
题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.我的解原创 2015-01-12 12:38:42 · 349 阅读 · 0 评论 -
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 us原创 2015-01-12 11:31:52 · 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,−原创 2015-01-18 11:06:40 · 616 阅读 · 0 评论 -
Linked List Circle题解
题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?我的解法:(1)算法思想:取快、慢两个指针,快指针一次走两步,慢指针一次走一步,如果存在circle,则快慢指针一定会相遇,否则不会相遇。原创 2015-01-15 14:36:36 · 492 阅读 · 0 评论 -
Maximum Depth of Binary Tree
题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.我的解法:(1)算法思想:递归,对于一个结点,原创 2015-01-12 12:14:18 · 477 阅读 · 0 评论