2013年11月4日

Valid Palindrome

摘要: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a good question to 阅读全文

posted @ 2013-11-04 22:56 waruzhi 阅读(130) 评论(0) 推荐(0) 编辑

Surrounded Regions

摘要: 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-11-04 22:34 waruzhi 阅读(180) 评论(0) 推荐(0) 编辑

Palindrome Partitioning

摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]思路:深搜代码: 1 bool isPalindrome(string s){ 2 in 阅读全文

posted @ 2013-11-04 21:45 waruzhi 阅读(132) 评论(0) 推荐(0) 编辑

Clone Graph

摘要: Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use#as a separator for each node, and,as a separator for node label and each neighbor of the node.As an example, consider the serialized g 阅读全文

posted @ 2013-11-04 18:48 waruzhi 阅读(230) 评论(0) 推荐(0) 编辑

Copy List with Random Pointer

摘要: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.思路:直接点的思路是根据原链表的next指针构建新链表,并通过一个map建立新旧链表的对应关系,再设置random指针。但是这样的问题是需要额外的map的空间。另一个改进的方法是在原链表的节点中间插入新链表的节点,对应关系隐含在里面,最后再把两个链表拆开。最开始一直runti 阅读全文

posted @ 2013-11-04 16:31 waruzhi 阅读(222) 评论(0) 推荐(0) 编辑

Merge Two Sorted Lists

摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.代码: 1 ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Sol... 阅读全文

posted @ 2013-11-04 11:13 waruzhi 阅读(139) 评论(0) 推荐(0) 编辑

Jump Game II

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

Merge k Sorted Lists

摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:二分转化为两个链表的归并,复杂度为(kn)。代码: 1 ListNode *merge2Lists(ListNode *l1, ListNode *l2){ 2 if(l1 == NULL) 3 return l2; 4 if(l2 == NULL) 5 return l1; 6 ListNode... 阅读全文

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

导航