上一页 1 ··· 5 6 7 8 9 10 下一页
摘要: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].Example 2:Given [1,2],[3,5],[ 阅读全文
posted @ 2012-09-13 22:00 ETCOW 阅读(622) 评论(0) 推荐(0) 编辑
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.needle in the haystack 大海捞针的意思其实就是找出 “短字符串” 在 “长字符串” 中的位置。 1 public static string strStr(string haystack, string needle) 2 { 3 if (haystack.Length == 0) 4... 阅读全文
posted @ 2012-09-07 05:47 ETCOW 阅读(1420) 评论(2) 推荐(0) 编辑
摘要: The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, given n = 2, return [0,1,3,2]. Its gray c 阅读全文
posted @ 2012-09-07 04:58 ETCOW 阅读(529) 评论(0) 推荐(0) 编辑
摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()" 1 public static List<string> GenerateParentheses 阅读全文
posted @ 2012-09-06 05:00 ETCOW 阅读(487) 评论(2) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space.JAVA 正解如下: 1 public class Solution { 2 public int firstMissingPositive(int[] A) { 3 // Start ... 阅读全文
posted @ 2012-09-06 04:37 ETCOW 阅读(494) 评论(9) 推荐(1) 编辑
摘要: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a character"abc" -> "bbdc" : 阅读全文
posted @ 2012-08-30 00:47 ETCOW 阅读(1353) 评论(1) 推荐(0) 编辑
摘要: Divide two integers without using multiplication, division and mod operator. 1 public static int Divid(int dividend, int divisor) 2 { 3 bool neg = false; 4 uint uint_dividend; 5 uint uint_divisor; 6 7 if (dividend < 0) 8 { 9 ... 阅读全文
posted @ 2012-08-29 22:36 ETCOW 阅读(325) 评论(0) 推荐(0) 编辑
摘要: A message containing letters from A-Z is 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 阅读全文
posted @ 2012-08-29 05:50 ETCOW 阅读(387) 评论(0) 推荐(0) 编辑
摘要: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文
posted @ 2012-08-29 05:22 ETCOW 阅读(490) 评论(0) 推荐(0) 编辑
摘要: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water 阅读全文
posted @ 2012-08-29 05:00 ETCOW 阅读(290) 评论(1) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 下一页