摘要:
There are a row of houses, each house can be painted with three colors red, blue and green. The cost of painting each house with a certain color is di... 阅读全文
摘要:
Merge two given sorted integer array A and B into a new sorted integer array.ExampleA=[1,2,3,4]B=[2,4,5,6]return [1,2,2,3,4,4,5,6]ChallengeHow can you... 阅读全文
摘要:
Given a unsorted array with integers, find the median of it. A median is the middle number of the array after it is sorted. If there are even numbers ... 阅读全文
摘要:
stair climbing, print out all of possible solutions of the methods to climb a stars, you are allowed climb one or two steps for each time; what is tim... 阅读全文
摘要:
Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguou... 阅读全文
摘要:
Reverse Integer那道题会考虑溢出,因为那是reverse each digit,这里不会溢出,因为reverse的是each bit Q:如果该方法被大量调用,或者用于处理超大数据(Bulk data)时有什么优化方法?A:这其实才是这道题的精髓,考察的大规模数据时算法最基本的优化方法 阅读全文
摘要:
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit i... 阅读全文
摘要:
Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the ... 阅读全文
摘要:
Given an array with integers.Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest.Return the largest difference.NoteThe ... 阅读全文
摘要:
Given an array of integers, the majority number is the number that occurs more than 1/3 of the size of the array.Find it.NoteThere is only one majorit... 阅读全文
摘要:
Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes.The lowest common ancestor is the node with large... 阅读全文
摘要:
Algorithm:Count the number of occurrence of each character.Only one character with odd occurrence is allowed since in a palindrome maximum number of c... 阅读全文
摘要:
分析:就是建立一个boolean array来记录array里面每个元素的访问情况,遇到访问过的元素就停止visiting,返回未访问的结点个数 1 public int visiting(int[] A, int N) { 2 if (A==null || A.length==0) ret... 阅读全文
摘要:
Given two strings, find the longest common substring.Return the length of it.NoteThe characters in substring should occur continiously in original str... 阅读全文
摘要:
Given two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.ExampleFor "ABCD" and "EDCA", the LCS is "A" (... 阅读全文
摘要:
Ugly number is a number that only have factors3,5and7.Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7.The ... 阅读全文
摘要:
Find K-th largest element in an array.NoteYou can swap elements in the arrayExampleIn array [9,3,2,4,8], the 3rd largest element is 4In array [1,2,3,4... 阅读全文
摘要:
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.NoteYou are not necessary to keep ... 阅读全文
摘要:
Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tree.ExampleGi... 阅读全文
摘要:
Remove Duplicates from unsorted array,它的错误在于9-10行k out of bound,改成下面这样就没问题了 1 public class removeDuplicates { 2 public static int[] remove(int[] a... 阅读全文
摘要:
这道题在Best Time to Buy and Sell Stock III做过,那道题只是把k取了2而已 递推式依然是 local[i][j]=max(global[i-1][j-1]+max(diff,0),local[i-1][j]+diff), global[i][j]=max(local 阅读全文
摘要:
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:... 阅读全文
摘要:
Consider the problem of storing n books on shelves in a library. The order of the books is fixedby the cataloging system and so cannot be rearraged. T... 阅读全文
摘要:
Insertion sortis a simplesorting algorithmthat builds the finalsorted array(or list) one item at a time. It is much less efficient on large lists than... 阅读全文
摘要:
As the title described, you should only use two stacks to implement a queue's actions.The queue should support push(element), pop() and top() where po... 阅读全文