摘要: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...
阅读全文
摘要: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)....
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要:Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.Show TagsSOLUTION 1:解法很直观。先找到最小长度,然后逐个字母遍历,...
阅读全文
摘要:Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [...
阅读全文
摘要: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....
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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 \ ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:WordLadder解题报告Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only...
阅读全文
摘要:N-Queens II (LEVEL 4 难度级别,最高级5)Follow up for N-Queens problem.Now, instead outputting board configurations, return the totalnumber of distinct solutio...
阅读全文
摘要:【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...
阅读全文
摘要:Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.SOLUTION 1:注意越界后返回0.先用l...
阅读全文
摘要: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 ...
阅读全文
摘要:Insertion Sort ListSort a linked list using insertion sort.SOLUTION: 使用一个dummynode 创建一个新的链,将旧的节点插入到新链中即可,相当简单哦! 1 /** 2 * Definition for singly-linke...
阅读全文
摘要: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...
阅读全文