上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 43 下一页
摘要: 数组al[0...mid-1]和al[mid...num-1]两个部分都已经分别排好序。要求合并使得整个数组al有序。请给出合并merge的代码。要求空间复杂度为O(1)。 1 /* 2 数组a[begin, mid] 和 a[mid+1, end]是各自有序的,对两个子段进行Merge得到a[begin , end]的有序数组。 要求空间复杂度为O(1) 3 方案: 4 1、两个有序段位A和B,A在前,B紧接在A后面,找到A的第一个大于B[0]的数A[i], A[0...i-1]相当于merge后的有效段,在B中找到第一个大于A[i]的数B[j], 5 对数组A[i...j-1]循环右移j- 阅读全文
posted @ 2013-09-12 16:23 feiling 阅读(306) 评论(0) 推荐(0) 编辑
摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文
posted @ 2013-09-09 23:35 feiling 阅读(408) 评论(0) 推荐(0) 编辑
摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文
posted @ 2013-09-08 20:05 feiling 阅读(391) 评论(0) 推荐(0) 编辑
摘要: leetcode上关于permutation有如下几题Permutation SequenceNext PermutationPermutationsPermutations II 阅读全文
posted @ 2013-09-07 22:46 feiling 阅读(296) 评论(0) 推荐(0) 编辑
摘要: Give a string, which only contains a-z. List all the permutation of upcase and lowcase.For example, str = "ab", the output should be"ab", "aB", "Ab", "AB"for str = "abc", the output should be"abc", "abC", "aBc" 阅读全文
posted @ 2013-09-07 16:28 feiling 阅读(391) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minimum n 阅读全文
posted @ 2013-09-06 15:03 feiling 阅读(727) 评论(0) 推荐(0) 编辑
摘要: The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I GY I RAnd then read line by line:"PAHNAPLSIIGYIR"Write the code that will take a string and 阅读全文
posted @ 2013-09-06 11:36 feiling 阅读(717) 评论(0) 推荐(0) 编辑
摘要: Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X XX X X 阅读全文
posted @ 2013-09-05 19:24 feiling 阅读(2167) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.» Solve this problem[解题思路]从前往后扫描,用一个临时变量记录分段数字。如果当前比前一个大,说明这一段的值应该是当前这个值减去上一个值。比如IV = 5 – 1否则,将当前值加入到结果中,然后开始下一段记录。比如VI = 5 + 1, II=1+1 1 public static int romanToInt(String s) { 2 // St... 阅读全文
posted @ 2013-09-04 22:54 feiling 阅读(210) 评论(0) 推荐(0) 编辑
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 1 public String intToRoman(int num) { 2 // Start typing your Java solution below 3 // DO NOT write main() function 4 StringBuffer result = new StringBuffer(); 5 ... 阅读全文
posted @ 2013-09-04 22:31 feiling 阅读(240) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 43 下一页