![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构&算法
mingyangdai
这个作者很懒,什么都没留下…
展开
-
113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2017-12-13 08:40:28 · 117 阅读 · 0 评论 -
348. Design Tic-Tac-Toe
Design a Tic-tac-toe game that is played between two players on a n x n grid.You may assume the following rules:A move is guaranteed to be valid and is placed on an empty block.Once a winning co原创 2017-11-28 08:55:18 · 365 阅读 · 0 评论 -
127. Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed a原创 2017-12-24 22:30:48 · 102 阅读 · 0 评论 -
75. 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原创 2017-12-16 16:50:49 · 119 阅读 · 0 评论 -
101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2/ \ / \3 4 4 3But the follo原创 2017-12-30 22:49:21 · 104 阅读 · 0 评论 -
110. Balanced Binary Tree
Given 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 subtrees of every node never differ原创 2017-12-17 10:35:00 · 104 阅读 · 0 评论 -
13. Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.discuss中vote最高public int romanToInt(String s) { int nums[]=new int[s.l原创 2017-12-31 20:40:11 · 151 阅读 · 0 评论 -
8. String to Integer (atoi)
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原创 2018-01-02 09:08:36 · 112 阅读 · 0 评论 -
173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()原创 2018-01-11 22:06:45 · 148 阅读 · 0 评论 -
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order 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原创 2018-01-03 09:04:10 · 94 阅读 · 0 评论 -
236. Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes原创 2017-12-06 22:06:51 · 91 阅读 · 0 评论 -
198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent hou原创 2017-11-27 21:48:07 · 85 阅读 · 0 评论 -
120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4],原创 2017-11-27 21:44:31 · 131 阅读 · 0 评论 -
70. 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?Note: Given n will be a positive原创 2017-11-25 23:24:18 · 114 阅读 · 0 评论 -
300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101]原创 2017-11-26 11:07:46 · 127 阅读 · 0 评论 -
206. Reverse Linked List
Reverse a singly linked list.A linked list can be reversed either iteratively or recursively. Could you implement both?单链表反转 public ListNode reverseList(ListNode head) { ListNode pre原创 2017-12-05 22:29:19 · 104 阅读 · 0 评论 -
138. 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.深拷贝带有random指针的linkedlist 第一种解法原创 2017-11-29 08:37:25 · 110 阅读 · 0 评论 -
204. Count Primes
Count the number of prime numbers less than a non-negative number, n.大致思路差不多 答案要简洁一些 注意结束条件 不是 ipublic int countPrimes(int n) { boolean[] notPrime = new boolean[n]; int count = 0;原创 2017-12-04 22:29:37 · 82 阅读 · 0 评论 -
270. Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target value is a floating point.You are guaranteed to have only one u原创 2017-12-03 15:15:38 · 99 阅读 · 0 评论 -
116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right nod原创 2017-12-22 23:18:16 · 106 阅读 · 0 评论 -
63. 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 and 0 respectively in the grid原创 2017-11-26 23:25:57 · 92 阅读 · 0 评论 -
416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array e原创 2017-12-14 21:56:16 · 90 阅读 · 0 评论 -
285. Inorder Successor in BST
Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null.做出来了 但是需要遍历整棵树 下面的基于原创 2018-01-13 21:53:05 · 157 阅读 · 0 评论 -
238. 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原创 2017-12-29 15:13:07 · 95 阅读 · 0 评论 -
24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2018-01-05 09:44:21 · 140 阅读 · 0 评论 -
266. Palindrome Permutation
Given a string, determine if a permutation of the string could form a palindrome.For example,"code" -> False, "aab" -> True, "carerac" -> True.判断一个字符串的字母排列之后是否能组成回文字符串很快就做出来了 思路是回文字符串中的字符都是成对...原创 2018-03-30 08:59:34 · 147 阅读 · 0 评论 -
243. Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.For example,Assume that words = ["practice", "makes", "perfect", "coding", "makes"...原创 2018-03-31 21:08:29 · 130 阅读 · 0 评论 -
273. Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand Three...原创 2018-03-28 09:16:38 · 197 阅读 · 0 评论 -
567. Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Example ...原创 2018-05-30 09:12:02 · 226 阅读 · 0 评论 -
128. Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Ex...原创 2018-07-27 08:36:02 · 155 阅读 · 0 评论 -
681. Next Closest Time
Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.You may assume the given input str...原创 2018-08-18 21:23:38 · 154 阅读 · 0 评论 -
635. Design Log Storage System
You are given several logs that each log contains a unique id and timestamp. Timestamp is a string that has the following format: Year:Month:Day:Hour:Minute:Second, for example, 2017:01:01:23:59:59. A...原创 2018-09-08 09:18:18 · 281 阅读 · 0 评论 -
539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.Example 1:Input: ["23:59","00:00"]Output: 1Note...原创 2018-10-07 17:20:01 · 184 阅读 · 0 评论 -
394. Decode String
Given an encoded string, return it's decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is gua...原创 2018-09-28 21:54:36 · 198 阅读 · 0 评论 -
654. Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree constructed from ...原创 2018-03-22 22:23:46 · 123 阅读 · 0 评论 -
56. 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].合并数组写的和答案差不多 但是答案中的排序 用到java8特性 比较简洁 public List<Interval&g...原创 2018-02-25 22:02:28 · 114 阅读 · 0 评论 -
162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that cas...原创 2018-02-20 08:19:02 · 137 阅读 · 0 评论 -
46. Permutations
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原创 2018-01-15 23:21:05 · 232 阅读 · 0 评论 -
71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"三刷简化了一下代码 使用jdk1.8新特性 switch支持String public Str原创 2017-11-18 15:00:20 · 86 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \原创 2018-01-07 22:55:43 · 131 阅读 · 0 评论