上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 17 下一页

2013年11月4日

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 阅读(181) 评论(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 阅读(133) 评论(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 阅读(231) 评论(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 阅读(225) 评论(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 阅读(140) 评论(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 阅读(196) 评论(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 阅读(157) 评论(0) 推荐(0) 编辑

2013年11月3日

N-Queens

摘要: 代码: 1 vector > result; 2 void search(int line, int total, vector &v, vector &col, vector &left, vector &right){ 3 if(line == total){ 4 result.push_back(v); 5 return; 6 } 7 int i; 8 for(i = 0; i > solveNQueens(int n) {23 // IMPO... 阅读全文

posted @ 2013-11-03 22:49 waruzhi 阅读(194) 评论(0) 推荐(0) 编辑

N-Queens II

摘要: 代码: 1 int result; 2 void search(int line, int total, vector &col, vector &left, vector &right){ 3 if(line == total){ 4 result++; 5 return; 6 } 7 int i; 8 for(i = 0; i col(n, true), left(2*n-1, true), right(2*n-1, true);25 searc... 阅读全文

posted @ 2013-11-03 22:46 waruzhi 阅读(200) 评论(0) 推荐(0) 编辑

Reorder List

摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}.思路:代码: 1 void reorderList(ListNode *head) { 2 // IMPORTANT: Please reset any member data you de... 阅读全文

posted @ 2013-11-03 21:34 waruzhi 阅读(202) 评论(0) 推荐(0) 编辑

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 17 下一页

导航