Lintcode
文章平均质量分 66
nicaishibiantai
这个作者很懒,什么都没留下…
展开
-
Lintcode - Topological Sorting
Thoughts:1. For each node in the graph, construct a map with node as key, and number of parent nodes as value2. Looping through left nodes and see if its indegree is 0: if so, remove the node from原创 2015-01-28 14:56:22 · 2340 阅读 · 0 评论 -
Lintcode - k sum II
Given n unique integers, number k (1ExampleGiven [1,2,3,4], k=2, target=5, [1,4] and [2,3] are possible solutions. public ArrayList> kSumII(int A[], int k, int target) { Array原创 2015-02-09 14:42:57 · 1836 阅读 · 0 评论 -
Lintcode - Previous Permutation
Given a list of integers, which denote a permutation.Find the previous permutation in ascending order.NoteThe list may contains duplicate integers.ExampleFor [1,3,2,3], the pre原创 2015-02-13 15:21:52 · 4822 阅读 · 0 评论 -
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 subarray should contain at least on原创 2015-03-20 13:02:48 · 4608 阅读 · 0 评论 -
Lintcode - Backpack II
Given n items with size A[i] and value V[i], and a backpack with size m. What's the maximum value can you put into the backpack?NoteYou cannot divide item into small pieces and the total siz原创 2015-03-17 13:13:10 · 2327 阅读 · 0 评论 -
Lintcode - Maximum Subarray III
Given an array of integers and a number k, find knon-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.NoteThe su原创 2015-03-24 05:21:00 · 4361 阅读 · 1 评论 -
Lintcode - Minimum Adjustment Cost
Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array before adjustment is A, the array after adjust原创 2015-02-17 15:39:03 · 3411 阅读 · 0 评论 -
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 3th largest element is 4ChallengeO(n) time, O(1) space原创 2015-01-30 12:07:30 · 1823 阅读 · 0 评论 -
Lintcode - Count digits
Count the number of k's between 0 and n. k can be 0 - 9.Exampleif n=12, in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], we have FIVE 1's (1, 10, 11, 12)see: http://www.hawstein.com/post原创 2015-02-01 09:22:12 · 3293 阅读 · 0 评论 -
Lintcode - Segment Tree Build
The structure of Segment Tree is a binary tree which each node has two attributes start andend denote an segment / interval.start and end are both integers, they should be assigned in following原创 2015-05-03 07:13:22 · 1482 阅读 · 0 评论 -
Lintcode - Segment Tree Query
For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores an extra attributemax to denote the maximum number in the interval o原创 2015-05-03 07:17:19 · 1637 阅读 · 0 评论 -
Lintcode - Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in this node's interval.Implement a modify function with three parameter root, index and value to原创 2015-05-03 07:39:22 · 1073 阅读 · 0 评论 -
Lintcode - Convert Expression to Polish Notation
Given an expression string array, return the Polish notation of this expression. (remove the parentheses)ExampleFor the expression [(5 − 6) * 7] (which represented by ["(", "5", "−", "6", ")原创 2015-05-15 13:12:13 · 2059 阅读 · 0 评论 -
Lintcode - Convert Expression to Reverse Polish Notation
Given an expression string array, return the Polish notation of this expression. (remove the parentheses)ExampleFor the expression [(5 − 6) * 7] (which represented by ["(", "5", "−", "6", ")原创 2015-05-15 13:10:32 · 2074 阅读 · 0 评论 -
Lintcode - Remove Node in Binary Search Tree
Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in the binary search tree, do nothing. You should kee原创 2015-02-09 11:33:08 · 1808 阅读 · 0 评论 -
Lintcode - Majority Number III
Given an array of integers and a number k, the majority number is the number that occurs more than 1/k of the size of the array. Find it.NoteThere is only one majority number in the array.原创 2015-02-08 14:32:07 · 4052 阅读 · 1 评论 -
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 majority number in the arrayExample原创 2015-02-08 09:04:09 · 1933 阅读 · 0 评论 -
Lintcode - sort colors II
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.NoteYou are not s原创 2015-01-30 14:02:34 · 3454 阅读 · 1 评论 -
Lintcode - Product of Array Exclude Itself
Given an integers array A.Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B without divide operation.ExampleFor A=[1, 2, 3], B is [6, 3, 2] public ArrayList produ原创 2015-01-30 13:14:53 · 3191 阅读 · 1 评论 -
Lintcode - Longest common subsequence
Given two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.样例For "ABCD" and "EDCA", the LCS is "A" (or D or C), return 1For "ABCD" and "EACB"原创 2015-02-04 13:05:16 · 1312 阅读 · 0 评论 -
Lintcode - Interleaving Positive and Negative Numbers
Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.You are not necessary to keep the original order or positive integers or negat原创 2015-02-03 13:02:45 · 2357 阅读 · 0 评论 -
Lintcode - Longest common substring
Given two strings, find the longest common substring.Return the length of it.注意The characters in substring should occur continiously in original string. This is different with subsequnce.原创 2015-02-03 13:23:52 · 1436 阅读 · 0 评论 -
Lowest common ancestor
This code is only valid if A and B exist in the tree public TreeNode lowestCommonAncestor(TreeNode root, TreeNode A, TreeNode B) { if (root == null) { return null; }原创 2015-02-05 13:27:46 · 1034 阅读 · 0 评论 -
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 in the array, return the N/2-th number aft原创 2015-02-05 15:51:05 · 3589 阅读 · 0 评论 -
Lintcode - Sort Letters by Case
Given a string which contains only letters. Sort it by lower case first and upper case second.NoteIt's not necessary to keep the original order of lower-case letters and upper case letters.原创 2015-02-08 07:16:17 · 1981 阅读 · 0 评论 -
Lintcode - Heapify
Given an integer array, heapify it into a min-heap array.For a heap array A, A[0] is the root of heap, and for each A[i], A[i * 2 + 1] is the left child of A[i] and A[i * 2 + 2] is the right child原创 2015-02-08 08:34:14 · 2278 阅读 · 0 评论 -
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 largest sum.NoteThe subarray shoul原创 2015-02-08 15:12:28 · 4113 阅读 · 0 评论 -
Lintcode - MedianII
Numbers keep coming, return the median of numbers at every time a new number added.ExampleFor numbers coming list: [1, 2, 3, 4, 5], return [1, 1, 2, 2, 3]For numbers coming list: [4, 5, 1, 3原创 2015-02-08 06:57:48 · 827 阅读 · 0 评论 -
Lintcode - Serialization and Deserialization Of Binary Tree
Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called 'serialization' and reading back from the file to reconstruct the exact same binary原创 2015-02-09 09:09:26 · 1329 阅读 · 0 评论 -
Lintcode - Expression Evaluation
Given an expression string array, return the final result of this expressionExampleFor the expression 2*6-(23+7)/(1+2), input is[ "2", "*", "6", "-", "(", "23", "+", "7", ")", "/", (原创 2015-05-15 09:46:44 · 3049 阅读 · 1 评论