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 and it costs cost[i] of gas to travel from statio
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 and it costs cost[i] of gas to travel from statio
Palindrome PartitioningGiven a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example:Given s = “aab”,Return 1
Sum Root to Leaf NumbersGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the nu
Best Time to Buy and Sell Stock IISay you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many tran
Flatten Binary Tree to Linked ListGiven a binary tree, flatten it to a linked list in-place. For example:Given 12345 1 / \ 2 5 / \ \3 4 6 The flattened tree should look like: 1234567891
Path Sum IIGiven 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, 1234567 5 / \ 4 8
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 提示 解題應用 DepthFirstSearch InorderTravel
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST. 提示 解題應用 DepthFirstSearch InorderTravel Default:12
Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 提
Binary Tree Zigzag Level Order TraversalGiven 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 alternate
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 keys less
Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example:Given n = 3, your program should return all 5 unique B
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. 123451 3 3
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes’ values. For example:Given binary tree [1,null,2,3], 123451 \ 2 /3 return [1,3,2]. Note: Recursive solutio
Restore IP AddressesGiven a string containing only digits, restore it by returning all possible valid IP address combinations. For example:123Given "25525511135",return ["255.255.11.13
Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass. For example:123Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2-&
Subsets IIGiven a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example:If nums = [1,2,2], a
Partition ListGiven 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 node
Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example:12Given 1->2->3-