上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 51 下一页
2014年2月10日
摘要: String to Integer (atoi)2014.2.10 02:23Implementatoito 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 (i 阅读全文
posted @ 2014-02-10 02:37 zhuli19901106 阅读(195) 评论(0) 推荐(0) 编辑
摘要: Longest Palindromic Substring2014.2.10 00:57Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring.Solution1: My first solution to this problem is the brute-force version, with O(n^2) . 阅读全文
posted @ 2014-02-10 01:36 zhuli19901106 阅读(317) 评论(0) 推荐(0) 编辑
2014年2月9日
摘要: Permutation Sequence2014.2.9 01:00The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, ret 阅读全文
posted @ 2014-02-09 01:17 zhuli19901106 阅读(230) 评论(0) 推荐(0) 编辑
2014年2月8日
摘要: First Missing Positive2014.2.8 23:43Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.Solution1: The first solution I thought of was hashing, using unordered_map. 阅读全文
posted @ 2014-02-08 23:58 zhuli19901106 阅读(167) 评论(0) 推荐(0) 编辑
摘要: Distinct Subsequences2014.2.8 22:11Given 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 remai 阅读全文
posted @ 2014-02-08 22:16 zhuli19901106 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Container With Most Water2014.2.8 21:37Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the conta 阅读全文
posted @ 2014-02-08 22:08 zhuli19901106 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 4Sum2014.2.8 20:58Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplic 阅读全文
posted @ 2014-02-08 21:15 zhuli19901106 阅读(205) 评论(0) 推荐(0) 编辑
2014年2月7日
摘要: 剑指Offer - 九度1524 - 复杂链表的复制2014-02-07 01:30题目描述:输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点)。输入:输入可能包含多个测试样例,输入以EOF结束。对于每个测试案例,输入的第一行为一个整数n (1 4 #include 5 using namespace std; 6 7 struct RandomListNode { 8 int label; 9 RandomListNode *next, *random; 10 RandomListNode(int ... 阅读全文
posted @ 2014-02-07 01:44 zhuli19901106 阅读(436) 评论(0) 推荐(0) 编辑
摘要: 剑指Offer - 九度1509 - 树中两个结点的最低公共祖先2014-02-07 01:04题目描述:给定一棵树,同时给出树中的两个结点,求它们的最低公共祖先。输入:输入可能包含多个测试样例。对于每个测试案例,输入的第一行为一个数n(0 7 #include 8 using namespace std; 9 10 const int MAXN = 10005; 11 // tree[x][0]: parent of node x 12 // tree[x][1]: left child of node x 13 // tree[x][2]: right child of node... 阅读全文
posted @ 2014-02-07 01:20 zhuli19901106 阅读(525) 评论(0) 推荐(0) 编辑
摘要: 剑指Offer - 九度1508 - 把字符串转换成整数2014-02-06 23:46题目描述:将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。输入:输入可能包含多个测试样例。对于每个测试案例,输入为一个合法或者非法的字符串,代表一个整数n(1 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 {10 int i;11 char s[100];12 int len;13 long long int n;14 int flag;15 bool suc;... 阅读全文
posted @ 2014-02-07 00:25 zhuli19901106 阅读(375) 评论(0) 推荐(0) 编辑
上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 51 下一页