随笔分类 -  LeetCode

上一页 1 2 3 4 5 6 7 下一页

LeetCode: Gas Station 解题报告
摘要:Gas StationThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank a... 阅读全文

posted @ 2014-12-22 23:18 Yu's Garden 阅读(2892) 评论(2) 推荐(2) 编辑

LeetCode: Binary Tree Level Order Traversal 解题报告
摘要:Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).... 阅读全文

posted @ 2014-12-22 20:24 Yu's Garden 阅读(529) 评论(0) 推荐(0) 编辑

LeetCode: Minimum Path Sum 解题报告
摘要: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 ... 阅读全文

posted @ 2014-12-22 20:06 Yu's Garden 阅读(718) 评论(0) 推荐(0) 编辑

LeetCode: Validate Binary Search Tree 解题报告
摘要: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 subtre... 阅读全文

posted @ 2014-12-21 21:08 Yu's Garden 阅读(7799) 评论(0) 推荐(1) 编辑

LeetCode: Longest Common Prefix 解题报告
摘要:Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.Show TagsSOLUTION 1:解法很直观。先找到最小长度,然后逐个字母遍历,... 阅读全文

posted @ 2014-12-21 19:15 Yu's Garden 阅读(588) 评论(0) 推荐(0) 编辑

LeetCode: Maximum Subarray 解题报告
摘要:Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [... 阅读全文

posted @ 2014-12-20 20:25 Yu's Garden 阅读(3399) 评论(1) 推荐(0) 编辑

LeetCode: Pow(x, n) 解题报告
摘要:Pow(x, n) Implement pow(x, n).SOLUTION 1:使用二分法。1. 负数的情况,使用以下的公式转化为求正数power,另外,考虑到MIN_VALUE可能会造成越界的情况,我们先将负数+1:X^(-n) = X^(n + 1) * XX^n = 1/(x^(-n))2.... 阅读全文

posted @ 2014-12-19 20:29 Yu's Garden 阅读(2321) 评论(0) 推荐(0) 编辑

LeetCode: Minimum Depth of Binary Tree 解题报告
摘要:Minimum Depth of Binary TreeGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root... 阅读全文

posted @ 2014-12-18 22:59 Yu's Garden 阅读(565) 评论(0) 推荐(0) 编辑

LeetCode: Binary Tree Maximum Path Sum 解题报告
摘要:Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the be... 阅读全文

posted @ 2014-12-18 22:31 Yu's Garden 阅读(4665) 评论(0) 推荐(0) 编辑

LeetCode: Binary Tree Postorder Traversal 解题报告
摘要: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 \ ... 阅读全文

posted @ 2014-12-18 21:51 Yu's Garden 阅读(518) 评论(0) 推荐(0) 编辑

LeetCode: Sum Root to Leaf Numbers 解题报告
摘要:Sum Root to Leaf Numbers Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-t... 阅读全文

posted @ 2014-12-18 21:27 Yu's Garden 阅读(623) 评论(0) 推荐(0) 编辑

LeetCode: Path Sum 解题报告
摘要:Path SumGiven 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 give... 阅读全文

posted @ 2014-12-18 21:10 Yu's Garden 阅读(525) 评论(0) 推荐(0) 编辑

LeetCode: Balanced Binary Tree 解题报告
摘要: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 tr... 阅读全文

posted @ 2014-12-18 20:54 Yu's Garden 阅读(930) 评论(0) 推荐(0) 编辑

LeetCode: Word Ladder解题报告
摘要:WordLadder解题报告Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only... 阅读全文

posted @ 2014-12-18 19:07 Yu's Garden 阅读(1079) 评论(2) 推荐(0) 编辑

LeetCode: N-Queens II 解题报告
摘要:N-Queens II (LEVEL 4 难度级别,最高级5)Follow up for N-Queens problem.Now, instead outputting board configurations, return the totalnumber of distinct solutio... 阅读全文

posted @ 2014-12-18 18:14 Yu's Garden 阅读(536) 评论(1) 推荐(0) 编辑

LeetCode: 【L4】N-Queens 解题报告
摘要:【L4】N-Queens解题报告N-Queens Total Accepted: 16418 Total Submissions: 63309 MySubmissionsThe n-queens puzzle is the problem of placing n queens on an n×nc... 阅读全文

posted @ 2014-12-17 19:09 Yu's Garden 阅读(994) 评论(0) 推荐(0) 编辑

LeetCode: Reverse Integer 解题报告
摘要:Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.SOLUTION 1:注意越界后返回0.先用l... 阅读全文

posted @ 2014-12-14 08:25 Yu's Garden 阅读(2148) 评论(0) 推荐(0) 编辑

LeetCode: Linked List Cycle II 解题报告
摘要:Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without ... 阅读全文

posted @ 2014-12-10 15:58 Yu's Garden 阅读(867) 评论(0) 推荐(0) 编辑

LeetCode: Insertion Sort List 解题报告
摘要:Insertion Sort ListSort a linked list using insertion sort.SOLUTION: 使用一个dummynode 创建一个新的链,将旧的节点插入到新链中即可,相当简单哦! 1 /** 2 * Definition for singly-linke... 阅读全文

posted @ 2014-12-10 15:38 Yu's Garden 阅读(643) 评论(0) 推荐(0) 编辑

LeetCode: Merge Two Sorted Lists 解题报告
摘要:Merge Two Sorted ListsMerge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the fir... 阅读全文

posted @ 2014-12-07 14:45 Yu's Garden 阅读(544) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 下一页

导航