随笔分类 - Lintcode
Lintcode: O(1) Check Power of 2
摘要:Using O(1) time to check whether an integer n is a power of 2.ExampleFor n=4, return trueFor n=5, return falseChallengeO(1) timeTags Expand 这道题考察bit m...
阅读全文
Lintcode: Minimum Adjustment Cost
摘要:1 Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.2 3 If the ...
阅读全文
Lintcode: Nth to Last Node in List
摘要:Find the nth to last element of a singly linked list. The minimum number of nodes in list is n.ExampleGiven a List 3->2->1->5->null and n = 2, return...
阅读全文
Lintcode: Merge Sorted Array II
摘要: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...
阅读全文
Lintcode: Median
摘要: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 ...
阅读全文
Lintcode: Maximum Subarray III
摘要: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...
阅读全文
Lintcode: Maximum Subarray II
摘要: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 ...
阅读全文
Lintcode: Maximum Subarray Difference
摘要: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 ...
阅读全文
Lintcode: Majority Number II
摘要: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...
阅读全文
Lintcode: Lowest Common Ancestor
摘要: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...
阅读全文
Lintcode: Longest Common Substring
摘要:Given two strings, find the longest common substring.Return the length of it.NoteThe characters in substring should occur continiously in original str...
阅读全文
Lintcode: Longest Common Subsequence
摘要: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" (...
阅读全文
Lintcode: Kth Prime Number (Original Name: Ugly Number)
摘要: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 ...
阅读全文
Lintcode: Kth largest Element
摘要: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...
阅读全文
Lintcode: k Sum
摘要:Given n distinct positive integers, integer k (k i) res[i][j][t] = 0;18 else res[i][j][t] = res[i-1][j][t];19 ...
阅读全文
Lintcode: k Sum II
摘要:Given n unique integers, number k (1> kSumII(int A[], int k, int target) { 9 // write your code here10 ArrayList> res = new ArrayList>...
阅读全文
Lintcode: Interleaving Positive and Negative Numbers
摘要:Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.NoteYou are not necessary to keep ...
阅读全文
Lintcode: Insert Node in a Binary Search Tree
摘要: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...
阅读全文
Lintcode: Heapify && Summary: Heap
摘要:Heap的介绍1,介绍2,要注意complete tree和full tree的区别, Heap是complete tree;Heap里面 i 的 children分别是 i*2+1 和 i*2+2,i 的 parent是 (i-1)/2 Heapify的基本思路就是:Given an array
阅读全文
Lintcode: Implement Queue by Stacks
摘要: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...
阅读全文
浙公网安备 33010602011771号