
leetcode
文章平均质量分 58
0_o_c
这个作者很懒,什么都没留下…
展开
-
recover-binary-search-tree
1、链接:recover-binary-search-tree 来源:牛客网Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n ) space is pretty原创 2017-10-17 08:40:39 · 317 阅读 · 0 评论 -
minimum-depth-of-binary-tree
1、链接:minimum-depth-of-binary-tree 来源:牛客网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.2、思原创 2017-10-20 22:08:39 · 220 阅读 · 0 评论 -
linked-list-cycle
1、链接:linked-list-cycle 来源:牛客网 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?2、思路:设置快慢指针,如果有cycle则会相遇,没有的话,快指针最终会走到tail 3、代码:public cl原创 2017-10-20 22:13:57 · 212 阅读 · 0 评论 -
sum-root-to-leaf-numbers
1、题目:sum-root-to-leaf-numbers 来源:牛客网 Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the n原创 2017-10-20 22:26:07 · 236 阅读 · 0 评论 -
populating-next-right-pointers-in-each-node-ii
1、populating-next-right-pointers-in-each-node-ii 来源:牛客网Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution原创 2017-10-20 23:17:26 · 279 阅读 · 0 评论 -
path-sum
1、链接:path-sum 来源:牛客网热度指数:5068时间限制:1秒空间限制:32768KGiven 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 path equals the given sum.For原创 2017-10-21 01:07:10 · 183 阅读 · 0 评论 -
unique-paths-ii
1、来源: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 as1and0respectivel原创 2017-10-28 03:12:00 · 303 阅读 · 0 评论 -
minimum-path-sum
1、来源:minimum-path-sumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move eithe原创 2017-10-28 02:28:25 · 235 阅读 · 0 评论 -
longest-common-prefix
1、来源:longest-common-prefix Write a function to find the longest common prefix string amongst an array of strings.2、思路在代码中写明了,直接看代码:package leetcode;import java.util.Arrays;/** * 对字符串排序,假如几个字符串前缀相同,那原创 2017-10-27 22:34:45 · 329 阅读 · 0 评论 -
permutations
1、题目: 链接: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].2、思路原创 2017-10-27 17:45:08 · 305 阅读 · 0 评论 -
unique-paths
1、链接:这里写链接内容 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 r原创 2017-10-20 02:25:30 · 237 阅读 · 0 评论 -
two-sum
1、来源:two-sumGiven an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the ta原创 2017-10-27 11:39:02 · 245 阅读 · 0 评论 -
symmetric-tree
1、链接: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原创 2017-10-17 22:42:21 · 231 阅读 · 0 评论 -
unique-binary-search-trees
1、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原创 2017-10-17 21:07:23 · 268 阅读 · 0 评论 -
path-sum-ii
1、链接: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 andsum = 22, 5原创 2017-10-21 01:17:48 · 242 阅读 · 0 评论 -
balanced-binary-tree
1、链接: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 subtre原创 2017-10-21 01:20:18 · 235 阅读 · 0 评论 -
rotate-list
1、来源:rotate-listGiven a list, rotate the list to the right by k places, where k is non-negative. For example: Given1->2->3->4->5->NULLand k =2, return4->5->1->2->3->NULL.2、思路,递归的本质是栈,例子中进栈1、2、3、4、5,原创 2017-10-24 08:55:40 · 257 阅读 · 0 评论 -
sort-colors
1、来源:sort-colorsGiven 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 t原创 2017-10-24 01:10:18 · 348 阅读 · 0 评论 -
climbing-stairs
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?2、思路:直接原创 2017-10-24 00:43:03 · 395 阅读 · 0 评论 -
partition-list
1、来源:partition-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 t原创 2017-10-24 00:31:44 · 331 阅读 · 0 评论 -
merge-sorted-array
1、来源:merge-sorted-array 牛客网Given two sorted integer arrays A and B, merge B into A as one sorted array.Note: You may assume that A has enough space to hold additional elements from B. The number of原创 2017-10-24 00:20:18 · 318 阅读 · 0 评论 -
binary-tree-zigzag-level-order-traversal
1、来源:binary-tree-zigzag-level-order-traversal牛客网Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alt原创 2017-10-24 00:06:22 · 313 阅读 · 0 评论 -
construct-binary-tree-from-preorder-and-inorder-traversal
1、来源:construct-binary-tree-from-preorder-and-inorder-traversal Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tr原创 2017-10-22 09:56:58 · 286 阅读 · 0 评论 -
path-sum
1、链接:path-sum 来源:牛客网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 path equals the given sum.For example:Given the below bi原创 2017-10-14 14:03:47 · 224 阅读 · 0 评论 -
sum-root-to-leaf-numbers
1、来源:sum-root-to-leaf-numbers 来源:牛客网Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the n原创 2017-10-14 13:48:46 · 284 阅读 · 0 评论 -
construct-binary-tree-from-inorder-and-postorder-traversal
1、链接:这里写链接内容来源:牛客网Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.2、思路,通过中序和后序来构建树:前序的第一个元素为当前根结点root;在后序中原创 2017-10-22 09:45:14 · 339 阅读 · 0 评论 -
word-break
1、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, given s =”leetcode”, dict原创 2017-10-29 01:58:57 · 271 阅读 · 0 评论 -
convert-sorted-list-to-binary-search-tree
1、链接:convert-sorted-list-to-binary-search-tree 来源:牛客网Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.2、思路:通过快慢指针找到中间结点,将中间结点设置为空(注意设置该结点为空,需原创 2017-10-21 01:32:57 · 235 阅读 · 0 评论 -
312. Burst Balloons
1、留坑吧。。。看不懂别人的代码原创 2016-09-16 03:25:15 · 481 阅读 · 0 评论 -
238. Product of Array Except Self c语言
1、题目链接:点击打开链接2、题目: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 ofnums except nums[i].Solve it wi原创 2016-08-08 22:02:27 · 346 阅读 · 0 评论 -
389. Find the Difference
1、来源:点击打开链接2、题目:Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.F原创 2016-09-10 01:32:52 · 278 阅读 · 0 评论 -
319. Bulb Switcher
1、来源:点击打开链接2、There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it'原创 2016-09-09 02:38:11 · 291 阅读 · 0 评论 -
leetcode-283. Move Zeroes c语言
1、来源:点击打开链接2、题目:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3原创 2016-07-20 07:49:49 · 566 阅读 · 0 评论 -
leetcode-292. Nim Game
1、来源:点击打开链接2、题目:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes th原创 2016-07-09 02:16:49 · 282 阅读 · 0 评论 -
LeetCode-94. Binary Tree Inorder Traversal
1、题目:点击打开链接2、题目:Given 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].原创 2016-07-08 01:31:44 · 335 阅读 · 0 评论 -
leetcode-258. Add Digits
1、来源:点击打开链接2、内容:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 +原创 2016-07-18 02:02:30 · 337 阅读 · 0 评论 -
leetcode-144. Binary Tree Preorder Traversal c++
1、来源:144. Binary Tree Preorder Traversal2、题目:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 /原创 2016-07-06 20:27:43 · 461 阅读 · 0 评论 -
leetcode-371. Sum of Two Integers
1、来源:点击打开链接2、题目:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.3、代码(主要还是参考了这里点击打开链接):class S原创 2016-07-17 00:44:16 · 344 阅读 · 0 评论 -
leetcode-100. Same Tree c++
1、题目来源:100. Same Tree2、题目: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原创 2016-07-06 07:05:34 · 414 阅读 · 0 评论 -
Leetcode-104. Maximum Depth of Binary Tree c语言
来源:104. 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 fart原创 2016-07-03 19:06:36 · 1032 阅读 · 0 评论