上一页 1 2 3 4 5 6 7 ··· 17 下一页

2013年12月4日

String to Integer (atoi)

摘要: Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文

posted @ 2013-12-04 15:21 waruzhi 阅读(151) 评论(0) 推荐(0) 编辑

Wildcard Matching

摘要: Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:bool i 阅读全文

posted @ 2013-12-04 13:10 waruzhi 阅读(174) 评论(0) 推荐(0) 编辑

2013年12月3日

Substring with Concatenation of All Words

摘要: You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S:"barfoothefoobarman"L:["foo", " 阅读全文

posted @ 2013-12-03 21:36 waruzhi 阅读(231) 评论(0) 推荐(0) 编辑

Minimum Window Substring

摘要: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the emtpy 阅读全文

posted @ 2013-12-03 18:54 waruzhi 阅读(238) 评论(0) 推荐(0) 编辑

2013年12月2日

Sort List

摘要: Sort a linked list inO(nlogn) time using constant space complexity.思路:归并排序。题目要求固定空间,不知道这种递归实现的算不算固定空间。代码: 1 ListNode *sortList(ListNode *head, int length){ 2 if(length next;14 }15 half = tmp->next;16 tmp->next = NULL;17 ListNode *first = sortList(head, l),... 阅读全文

posted @ 2013-12-02 19:47 waruzhi 阅读(187) 评论(0) 推荐(0) 编辑

Merge Intervals

摘要: Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].思路:先对数据进行排序,然后逐个插入。注意在使用sort的时候,最开始出现错误,后来把myCmp改成static的以后就解决了。代码: 1 int max(int a, int b){ 2 if(a > b) 3 return a; 4 return b; 5 ... 阅读全文

posted @ 2013-12-02 16:43 waruzhi 阅读(186) 评论(0) 推荐(0) 编辑

2013年11月28日

Decode Ways

摘要: 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-11-28 11:36 waruzhi 阅读(188) 评论(0) 推荐(0) 编辑

Evaluate Reverse Polish Notation

摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13&qu 阅读全文

posted @ 2013-11-28 09:15 waruzhi 阅读(235) 评论(0) 推荐(0) 编辑

2013年11月26日

Divide Two Integers

摘要: Divide two integers without using multiplication, division and mod operator.思路:直接的想法是用减法代替,但是减法在极端情况下肯定会超时,最多可能会有2^31。然后考虑用移位,对除数左移位,直到将要大于被除数时为止,然后记录当前值,并更新被除数,如此循环。需要注意的是,因为int的范围是-2^32到2^32,所以如果最小的负数取整数就会越界,所以使用unsigned int或者long long代替。代码: 1 int divide(int dividend, int divisor) { 2 ... 阅读全文

posted @ 2013-11-26 23:18 waruzhi 阅读(165) 评论(0) 推荐(0) 编辑

Candy

摘要: There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the minimum candies you mu 阅读全文

posted @ 2013-11-26 22:12 waruzhi 阅读(165) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 ··· 17 下一页

导航