原创 lowest node's LCA

給一個 二叉樹/多叉樹 , 求最深節點的最小公共父節點。 這題算是對LCA的一個擴展,由給定兩個點換成了最深兩個點,由二叉樹換成多樹。 難點1. 我們要返回什麼? 不難看出來, 最後要返回一個node,所以TreeNode 肯

原创 265. Paint House II

There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with

原创 334. Increasing Triplet Subsequence

Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. Formally the

原创 90. Subsets II

Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution s

原创 286. Walls and Gates

You are given a m x n 2D grid initialized with these three possible values. -1 - A wall or an obstacle.0 - A gate.INF

原创 274. H-Index

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the

原创 157. Read N Characters Given Read4

The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actual number of char

原创 Prime Number Combination Product

給一個質數數組,返回所有可能的product,順序不管 比如給 [2,3,5] 返回 [2,3,5,6,10,15,30] 數組中的數如果有重複則需要去重,不允許用set。 比如給 [2,2,2] 返回 [2,4,8],順序不用管

原创 269. Alien Dictionary

There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You

原创 209. Minimum Size Subarray Sum

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of wh

原创 128. Longest Consecutive Sequence

Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given

原创 398. Random Pick Index

Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assu

原创 43. Multiply Strings

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: The

原创 K closest point to the origin

Give n points on 2-D plane, find the K closest points to origin 13 public List<Point> KClosest(List<Point> input,

原创 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, wi