
LintCode
文章平均质量分 63
Geurney
这个作者很懒,什么都没留下…
展开
-
Unique Subsets
Unique SubsetsGiven a list of numbers that may has duplicate numbers, return all possible subsets.ExampleIf S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []原创 2015-03-26 16:14:19 · 658 阅读 · 0 评论 -
Find Min in Rotated Array
Find Min in Rotated ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may a原创 2015-03-27 17:34:30 · 596 阅读 · 0 评论 -
String 字符串题目
题目汇总:1. strStr A字符串中是否含有B字符串。遍历即可。2. Two Strings Are Anagrams A字符串中的字符是否和B字符串的字符一致(变位词)。数组自动初始化,先加后减。3. Anagrams 找出字符串数组里的变位词。由数组生成字符串key,存入hashmap。3. Compare Strings A字符串中的字符是否包含了B字符串的字符。数组自动原创 2015-07-17 11:10:02 · 686 阅读 · 0 评论 -
Square root
SqrtXImplement int sqrt(int x).Compute and return the square root of x.Examplesqrt(3) = 1sqrt(4) = 2sqrt(5) = 2sqrt(10) = 3ChallengeO(log(x))Solution:原创 2015-04-01 11:39:38 · 797 阅读 · 0 评论 -
Search 2D matrix II
Search 2D matrix IIWrite an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it.This matrix has the following properties: * Integers in each原创 2015-03-27 12:28:14 · 491 阅读 · 0 评论 -
Search Insert Position
Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume原创 2015-03-27 11:33:30 · 450 阅读 · 0 评论 -
Two Strings Are Anagrams
Two Strings Are Anagrams判断两个string里的字符和计数是否一致。Write a method anagram(s,t) to decide if two strings are anagrams or not.ExampleGiven s="abcd", t="dcab", return true.Challeng原创 2015-07-17 11:02:36 · 671 阅读 · 0 评论 -
Binary Search
Binary SearchFor a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity.If the target number does not exist in the array,原创 2015-03-27 05:48:33 · 442 阅读 · 0 评论 -
Find Peak Element
Find Peak ElementThere is an integer array which has the following features: * The numbers in adjacent positions are different. * A[0] A[A.length - 1].We define a position P i原创 2015-03-27 15:18:04 · 464 阅读 · 0 评论 -
Search 2D matrix
Search 2D matrixWrite an efficient algorithm that searches for a value in an m x n matrix.This matrix has the following properties: * Integers in each row are sorted from left to righ原创 2015-03-27 11:44:44 · 549 阅读 · 0 评论 -
Rotate String
Rotate StringGiven a string and an offset, rotate string by offset. (rotate from left to right)ExampleGiven "abcdefg"for offset=0, return "abcdefg"for offset=1, return "gabcdef"for原创 2015-04-01 00:41:35 · 749 阅读 · 0 评论 -
Reverse Words in a String
Reverse Words in a String翻转string里的单词顺序。Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Solution: public原创 2015-07-18 10:10:14 · 756 阅读 · 0 评论 -
Longest Words
Longest Words找出数组内最长的stringGiven a dictionary, find all of the longest words in the dictionary.ExampleGiven{ "dog", "google", "facebook", "internationalization", "blabla"}原创 2015-07-18 10:49:12 · 789 阅读 · 0 评论 -
Binary Search 二分查找
Binary Search 二分查找。在有序数组中(允许重复数字),查找第一个或最后一个目标数字。时间复杂度为O(logN)。循环方法和递归方法。原创 2015-07-16 11:08:00 · 920 阅读 · 0 评论 -
3 sum
3 Sum数组中3个数的和为指定值。Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Example原创 2015-07-18 15:09:05 · 734 阅读 · 0 评论 -
Median of two Sorted Arrays
Median of two Sorted Arrays在两个数组中找到中位数。There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays.ExampleGiven A=[1,2,3,4,5,6] and原创 2015-07-18 07:47:31 · 637 阅读 · 0 评论 -
Length of Last Word
Length of Last WordString里最后一个单词的长度Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word d原创 2015-07-18 11:06:46 · 711 阅读 · 0 评论 -
Recover Rotated Array
Recover Rotated ArrayGiven a rotated sorted array, recover it to sorted array in-place.Example[4, 5, 1, 2, 3] -> [1, 2, 3, 4, 5]ChallengeIn-place, O(1) extra space and O(n) t原创 2015-03-31 23:55:04 · 742 阅读 · 0 评论 -
Search in Rotated Array II
Search in Rotated Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to deter原创 2015-03-27 16:58:42 · 442 阅读 · 0 评论 -
Search in Rotated Sorted Array
Search in Rotated Sorted ArraySuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to原创 2015-03-27 16:45:17 · 473 阅读 · 0 评论 -
Permutations
PermutationsGiven a list of numbers, return all possible permutations.ExampleFor nums [1,2,3], the permutaions are: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],原创 2015-03-26 16:41:43 · 575 阅读 · 0 评论 -
Single Number
Single NumberGiven 2*n + 1 numbers, every numbers occurs twice except one, find it.ExampleGiven [1,2,2,1,3,4,3], return 4Solution异或: public int singleNumber(int[] A) { i原创 2015-03-27 02:31:22 · 502 阅读 · 0 评论 -
unique characters
unique charactersImplement an algorithm to determine if a string has all unique charactersExampleGiven "abc", return trueGiven "aab", return false原创 2015-03-26 15:44:40 · 654 阅读 · 0 评论 -
Single Number II
Single Numbe IIGiven 3*n + 1 numbers, every numbers occurs triple times except one, find it.ExampleGiven [1,1,2,3,3,3,2,2,4,1] return 4Solution: public int singleNumberII(int[] A)原创 2015-03-27 04:55:14 · 545 阅读 · 0 评论 -
Single Number III
Single Number IIIGiven 2*n + 2 numbers, every numbers occurs twice except two, find them.ExampleGiven [1,2,2,3,4,4,5,3] return 1 and 5Solution public List singleNumberIII(int[] A) {原创 2015-03-27 05:10:17 · 502 阅读 · 0 评论 -
Compare Strings
Compare StringsCompare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Caseletters.ExampleFor A = "ABCD", B原创 2015-03-27 15:42:00 · 614 阅读 · 0 评论 -
Unique Permutations
Unique PermutationsGiven a list of numbers with duplicate number in it. Find all unique permutations.ExampleFor numbers [1,2,2] the unique permutations are:[ [1,2,2], [2,1,2],原创 2015-03-26 17:26:51 · 640 阅读 · 0 评论 -
Find Min in Rotated Array II
Find Min in Rotated Array IISuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.The原创 2015-03-27 18:07:06 · 448 阅读 · 0 评论 -
Merge Sorted Array II
Merge Sorted Array IIGiven two sorted integer arrays A and B, merge B into A as one sorted array.NoteYou may assume that A has enough space (size that is greater or equal to m + n) to原创 2015-03-31 08:29:09 · 725 阅读 · 0 评论 -
Remove duplicates from sorted array
Remove duplicates from sorted arrayGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for anot原创 2015-03-31 04:32:43 · 474 阅读 · 0 评论 -
Remove duplicates from sorted array II
Remove duplicates from sorted array IIFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function sh原创 2015-03-31 04:49:55 · 575 阅读 · 0 评论 -
Merge Sorted Array
Merge Sorted ArrayMerge 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 o原创 2015-03-31 05:31:22 · 554 阅读 · 0 评论 -
2 sum
2 sumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the原创 2015-04-01 11:11:46 · 635 阅读 · 0 评论 -
strStr
strStr (easy)For a given source string and a target string, you should output the "first" index(from 0) of target string in source string.If target is not exist in source, just return -1.原创 2015-03-26 11:49:45 · 528 阅读 · 0 评论 -
Subsets
SubsetsGiven a set of distinct integers, return all possible subsets.原创 2015-03-26 14:54:53 · 746 阅读 · 0 评论 -
First Bad Version
First Bad Version Boolean数组中找到第一个true.The code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the follow原创 2015-07-17 06:28:56 · 615 阅读 · 0 评论 -
Search for a Range
Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.If the target is not found in the array, return [-1, -1].ExampleGive原创 2015-03-27 06:18:31 · 447 阅读 · 0 评论 -
Count and Say
Count and Say按规律生成stringThe count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11. 1个111 is read off原创 2015-07-18 11:50:11 · 893 阅读 · 0 评论