
leetcode
qq_34344061
这个作者很懒,什么都没留下…
展开
-
LeetCode 63.Unique Paths II
LeetCode 63.Unique Paths IIFollow 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 res原创 2018-01-30 16:06:34 · 216 阅读 · 0 评论 -
LeetCode 108.Convert Sorted Array to Binary Search Tree
LeetCode 108.Convert Sorted Array to Binary Search Tree题目来源:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/description/Given an array where elements are sorted in ascending or原创 2018-01-28 20:27:56 · 187 阅读 · 0 评论 -
LeetCode 110.Balanced Binary Tree
LeetCode 110.Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two sub原创 2018-01-28 15:31:13 · 186 阅读 · 0 评论 -
LeetCode 101 Symmetric Tree
LeetCode Symmetric Tree题目来源 https://leetcode.com/problems/symmetric-tree/description/Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this bi原创 2018-01-27 17:03:11 · 190 阅读 · 0 评论 -
LeetCode 100 Same Tree
LeetCode 100 Same Tree题目来源:https://leetcode.com/problems/same-tree/description/Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if原创 2018-01-27 16:32:54 · 172 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
LeetCode 53. Maximum Subarray题目来源:https://leetcode.com/problems/maximum-subarray/description/Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For原创 2018-01-26 19:35:07 · 154 阅读 · 0 评论 -
Leetcode 81 Search in Rotated Sorted Array II
Leetcode 81 Search in Rotated Sorted Array II题目来源:https://leetcode.com/problems/search-in-rotated-sorted-array-ii/description/ Follow up for “Search in Rotated Sorted Array”: What if duplicates a原创 2018-01-26 16:57:50 · 143 阅读 · 0 评论 -
LeetCode 34. Search for a Range
LeetCode 34. Search for a Range题目来源:https://leetcode.com/problems/search-for-a-range/description/Given an array of integers sorted in ascending order, find the starting and ending position of a given t原创 2018-01-26 13:46:41 · 228 阅读 · 0 评论 -
LeetCode 35 Search Insert Position
LeetCode 35 Search Insert Position题目来源:https://leetcode.com/problems/search-insert-position/description/Given a sorted array and a target value, return the index if the target is found. If not, return原创 2018-01-25 20:49:50 · 219 阅读 · 0 评论 -
LeetCode 109. Convert Sorted List to Binary Search Tree
LeetCode 109. Convert Sorted List to Binary Search Tree题目来源:https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/description/Given a singly linked list where elements are sorte原创 2018-01-28 20:29:41 · 151 阅读 · 0 评论 -
LeetCode 112 Path Sum
LeetCode 112 Path Sum题目来源:https://leetcode.com/problems/path-sum/description/Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the pa原创 2018-01-28 21:06:45 · 171 阅读 · 0 评论 -
LeetCode 144.Binary Tree Preorder Traversal
LeetCode 144.Binary Tree Preorder TraversalGiven a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,2,原创 2018-01-29 14:51:58 · 138 阅读 · 0 评论 -
LeetCode 62 Unique Paths
LeetCode 62 Unique Paths题目链接:https://leetcode.com/problems/unique-paths/description/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 m原创 2018-01-30 15:10:44 · 191 阅读 · 0 评论 -
LeetCode 64 .Minimum Path Sum
LeetCode 64 .Minimum Path Sum题目链接:https://leetcode.com/problems/minimum-path-sum/description/Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimiz原创 2018-01-30 14:40:56 · 222 阅读 · 0 评论 -
LeetCode 98.Validate Binary Search Tree
LeetCode 98.Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with k原创 2018-01-30 13:15:46 · 208 阅读 · 0 评论 -
LeetCode 95.Unique Binary Search Trees II
LeetCode 95.Unique Binary Search Trees II题目链接:https://leetcode.com/problems/unique-binary-search-trees-ii/description/Given an integer n, generate all structurally unique BST’s (binary search trees) th原创 2018-01-30 12:20:32 · 202 阅读 · 0 评论 -
LeetCode 96.Unique Binary Search Trees
LeetCode 96.Unique Binary Search TreesGiven 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原创 2018-01-29 19:48:51 · 175 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
LeetCode 69. Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4Output: 2Example 2:Input: 8Output: 2Explanation:原创 2018-01-29 16:01:06 · 263 阅读 · 0 评论 -
LeetCode 145. Binary Tree Postorder Traversal
LeetCode 145. Binary Tree Postorder TraversalGiven a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3return [3原创 2018-01-29 14:53:54 · 189 阅读 · 0 评论 -
LeetCode 94. Binary Tree Inorder Traversal
LeetCode 94. Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2]原创 2018-01-29 14:53:07 · 147 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
LeetCode 3. Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the原创 2018-01-25 20:31:45 · 129 阅读 · 0 评论 -
sort_List
1.Sort a linked list in O(n log n) time using constant space complexity.使用合并排序对单链表进行排序,时间复杂度为O(nlogn),使用插入排序对单链表进行排序,时间复杂度为O(n2);public class Sort_list { public ListNode findMiddle(ListNode head){原创 2018-01-04 21:01:58 · 228 阅读 · 0 评论 -
remove-nth-node-from-end-of-list
Given a linked list, remove the n th 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原创 2018-01-04 21:00:57 · 526 阅读 · 0 评论 -
MergeTwoSortedList
合并两个有序链表:package leetcode;import java.util.List;public class MergeTwoSortedList { public ListNode MergeTwoSortedList(ListNode l1,ListNode l2) { // TODO Auto-generated constructor stub原创 2018-01-04 20:59:54 · 140 阅读 · 0 评论 -
ReveseList
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given1->2->3->4->5->NULL, m = 2 and n = 4,return1->4->3->2->5->NULL.Note: Given m, n satisfy the following con原创 2017-11-24 12:11:09 · 180 阅读 · 0 评论 -
removeFromList1;
package leetcode;Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given1->1->2, return1->2. Given1->1->2->3->3, return1->2->3.题意:把重复的元素删除。原创 2017-11-24 12:09:45 · 376 阅读 · 0 评论 -
removeFromList
remove-duplicates-from-sorted-list:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given1->2->3->3->4->4->原创 2017-11-24 12:08:13 · 1395 阅读 · 0 评论 -
ParttiTion List 划分链表
ParttiTion List 划分链表Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the n原创 2017-11-22 19:53:27 · 351 阅读 · 0 评论 -
MergeTwoSortedList
合并两个有序链表:package leetcode;import java.util.List;public class MergeTwoSortedList { public ListNode MergeTwoSortedList(ListNode l1,ListNode l2) { // TODO Auto-generated constructor stub原创 2017-11-22 19:51:19 · 158 阅读 · 0 评论 -
Record_List
Recorder_Listhttps://www.nowcoder.com/questionTerminal/3d281dc0b3704347846a110bf561ef6bGiven a singly linked list L: L 0→L 1→…→L n-1→L n, reorder it to: L 0→L n →L 1→L原创 2018-01-04 21:04:04 · 1826 阅读 · 0 评论 -
Circle_List
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?判断一个单链表中是否存在环:采用快慢指针方法,若慢指针和快指针中间相遇,则一定存在环。public class Circle_List { public boolean ha原创 2018-01-04 21:05:03 · 318 阅读 · 0 评论 -
CircleList_2
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up: Can you solve it without using extra space?找出单链表中环开始的结点:(1)同Circle——List,使用快慢指针判断是否存在环,并找到两指针相遇原创 2018-01-04 21:06:15 · 250 阅读 · 0 评论 -
155. Min Stack
155. Min Stack题目链接:https://leetcode.com/problems/min-stack/description/Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto st原创 2018-01-25 20:28:45 · 168 阅读 · 0 评论 -
AddTwoNumbers
LeetCode 2 Add Two Numbers题目链接:https://leetcode.com/problems/add-two-numbers/description/You are given two non-empty linked lists representing two non-negative integers. The digits are stored in revers原创 2018-01-25 20:21:34 · 319 阅读 · 0 评论 -
Count and Say
Count and SayThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11. 11 is r原创 2018-01-24 13:10:59 · 164 阅读 · 0 评论 -
20 Valid Parentheses
20 Valid ParenthesesGiven a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}"原创 2018-01-24 12:35:58 · 136 阅读 · 0 评论 -
Two Sum和Three Sum
Two Sum和Three Sum1.Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may n原创 2018-01-24 12:29:20 · 328 阅读 · 0 评论 -
Longest Common Prefix
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.方法一:public String longestCommonPrefix(String[] strs) { int n=strs.length,j;原创 2018-01-24 12:25:32 · 238 阅读 · 0 评论 -
Generate Parentheses卡特兰数的应用:
卡特兰数的应用:(1)n对括号正确匹配数目:给定n对括号,求括号正确配对的字符串数,例如:0对括号:[空序列] 1种可能1对括号:() 1种可能2对括号:()() (()) 2种可能3对括号:((())) ()(()) ()()() (())() (()()) 5种可能那么问题来了,n对括号有多少种正确配对的可能呢?考虑n对括号时的任意一种配对方案,最后一个右括号有唯一的与之匹配的左括号,于是有唯一原创 2018-01-24 12:23:39 · 185 阅读 · 0 评论 -
leetcod第一题和第二题
1.Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.(mininum-depth-of-binary-tree):二叉树class S原创 2017-10-21 19:09:49 · 849 阅读 · 0 评论