- 博客(53)
- 收藏
- 关注
原创 Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return ...
2016-09-27 14:25:01 748
原创 Kth Smallest Element in a Sorted Matrix
Given anxnmatrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, no...
2016-09-27 12:41:04 403
原创 Design Phone Directory
Design a Phone Directory which supports the following operations:get: Provide a number which is not assigned to anyone.check: Check if a number is available or not.release: Recycle or release a
2016-09-26 08:12:06 801
原创 Flip Game II
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip two consecutive "++" into "--". Th
2016-09-24 10:56:36 296
原创 Design Twitter
Implement a simple twitter. Support the following method:postTweet(user_id, tweet_text). Post a tweet. getTimeline(user_id). Get the given user's most recently 10 tweets posted by himself, order by...
2016-09-24 07:10:54 304
原创 Bulb Switcher
There arenbulbs 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's off or turning off
2016-09-24 00:52:14 279
原创 Nth Digit
Find thenthdigit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:nis positive and will fit within the range of a 32-bit signed integer (n31).Example 1:Input
2016-09-23 13:56:58 1548
原创 Basic Calculator II
Implement a basic calculator to evaluate a simple expression string.The expression string contains onlynon-negativeintegers,+,-,*,/operators and empty spaces. The integer division should
2016-09-23 12:54:25 257
原创 Expression Add Operators
Given a string that contains only digits0-9and a target value, return all possibilities to addbinaryoperators (not unary)+,-, or*between the digits so they evaluate to the target value.
2016-09-22 14:56:37 276
原创 Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1
2016-09-22 13:40:03 215
原创 Mini Parser
Given a nested list of integers represented as a string, implement a parser to deserialize it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.
2016-09-22 12:54:33 280
原创 Shortest Word Distance II
This is afollow upofShortest Word Distance. The only difference is now you are given the list of words and your method will be calledrepeatedlymany times with different parameters. How would you
2016-09-21 14:45:25 443
原创 Decode String
Given an encoded string, return it's decoded string.The encoding rule is:k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. Note thatkis g...
2016-09-21 14:25:03 624
原创 Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The p...
2016-09-21 12:56:45 276
原创 Build Min Heap Using Array
Build min-heap using Array.思路1:首先明白heap的底层implementation就是array,从0开始的parent和left,right的关系为,如果现在的node index为i,那么parent index就是 (i-1)/2; left 为2*i+1, right为 2*i+2; ( i-1 ) / 2...
2016-09-21 11:30:13 734
原创 Flatten 2D Vector
Implement an iterator to flatten a 2d vector.For example,Given 2d vector =[ [1,2], [3], [4,5,6]]By callingnextrepeatedly untilhasNextreturns false, the order of elements returned
2016-09-20 13:46:51 454
原创 Longest Absolute File Path
Suppose we abstract our file system by a string in the following manner:The string"dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext"represents:dir subdir1 subdir2 file.extThe direc
2016-09-20 11:39:23 366
原创 Game of Life
According to theWikipedia's article: "TheGame of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given aboardwithm
2016-09-19 14:14:52 270
原创 Walls and Gates
You are given am x n2D grid initialized with these three possible values.-1- A wall or an obstacle.0- A gate.INF- Infinity means an empty room. We use the value231- 1 = 2147483647to repr
2016-09-19 13:07:46 365
原创 Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231- 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Thousand Th
2016-09-19 09:06:01 352
原创 Design Tic-Tac-Toe
Design a Tic-tac-toe game that is played between two players on anxngrid.You may assume the following rules:A move is guaranteed to be valid and is placed on an empty block.Once a winning
2016-09-19 08:16:19 525
原创 Binary Watch
A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit o
2016-09-19 06:51:03 1938
原创 Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin
2016-09-18 12:36:20 518
原创 Median of Two Sorted Arrays
There are two sorted arraysnums1andnums2of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1...
2016-09-15 13:21:23 287
原创 Trapping Rain water
Givennnon-negative integers representing an elevation map where the width of each bar is1, compute how much water it is able to trap after raining.ExampleExample 1:Input: [0,1,0]Output: 0...
2016-09-14 11:29:38 379
原创 Maximum Index
Given an array arr[], find the maximum j – i such that arr[j] > arr[i]Given an array arr[], find the maximum j – i such that arr[j] > arr[i].Examples: Input: {34, 8, 10, 3, 2, 80, 30, 33,
2016-09-13 10:26:03 357
原创 Line Reflection
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.Example 1:Given points = [[1,1],[-1,1]], return true.Example 2:Given poi
2016-09-13 07:41:00 313
原创 Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there existsi, j, ksuch thatarr[i]ar
2016-09-13 06:16:07 199
原创 Rotate Function
Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:
2016-09-13 04:34:52 1083
原创 Integer Replacement
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o
2016-09-13 03:08:07 819
原创 Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only le...
2016-09-11 11:40:17 453
原创 Meeting Rooms II
Given an array of meeting time intervals consisting of start and end times[[s1,e1],[s2,e2],...](si< ei), find the minimum number of conference rooms required.For example,Given[[0, 30],[5,...
2016-09-11 10:35:05 1045
原创 Implement Trie (Prefix Tree)
Implement a trie withinsert,search, andstartsWithmethods.Note:You may assume that all inputs are consist of lowercase lettersa-z.思路:首先建立一个TrieNode class,里面包含26个TireNode array,然后build trie...
2016-09-11 09:56:43 277
原创 Longest Substring with At Least K Repeating Characters
Find the length of the longest substringTof a given string (consists of lowercase letters only) such that every character inTappears no less thanktimes.Example 1:Input:s = "aaabb", k =
2016-09-11 08:19:28 1976
原创 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution
2016-09-10 13:14:07 303
原创 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0...
2016-09-10 07:16:31 426
原创 Nested List Weight Sum II
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.Each element is either an integer, or a list -- whose elements may also be integers or other lis
2016-09-10 05:25:19 465
原创 Shortest Word Distance III
This is afollow upofShortest Word Distance. The only difference is nowword1could be the same asword2.Given a list of words and two wordsword1andword2, return the shortest distance betwe
2016-09-10 04:45:32 317
转载 Implement Set using Array.
参考链接:http://faculty.washington.edu/moishe/javademos/ch03%20Code/jss2/ArraySet.java被Pivotal的面试官给问到了,trick的地方在于remove的那一块,要把最后的元素跟自己remove的元素进行互换,然后count--;//****************************************
2016-09-10 02:08:51 668
原创 Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list -- whose elements may also be integers or other lists.Example 1:Given the list...
2016-09-08 14:36:19 655
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人