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

2013年7月22日

摘要: Problem:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2... 阅读全文
posted @ 2013-07-22 13:24 freeneng 阅读(202) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does not matter)Analysis:Originally, I thought DFS may be a good solution. 阅读全文
posted @ 2013-07-22 12:53 freeneng 阅读(261) 评论(0) 推荐(0) 编辑
摘要: Problem:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 next == NULL)15 return head;16 17 ListNode dmy(-1), *p, *pm;18 ... 阅读全文
posted @ 2013-07-22 12:18 freeneng 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Problem: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" 阅读全文
posted @ 2013-07-22 05:43 freeneng 阅读(202) 评论(0) 推荐(0) 编辑

2013年7月21日

摘要: Problem:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2-> 阅读全文
posted @ 2013-07-21 13:01 freeneng 阅读(187) 评论(0) 推荐(0) 编辑
摘要: Problems:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Analysis:This problem is a bit different fro 阅读全文
posted @ 2013-07-21 07:27 freeneng 阅读(150) 评论(0) 推荐(0) 编辑

2013年7月20日

摘要: Problem:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboa 阅读全文
posted @ 2013-07-20 08:24 freeneng 阅读(229) 评论(0) 推荐(0) 编辑

2013年7月17日

摘要: Problem:Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]]Analysis:Treat it as a simulation problem. Use a "dir" variable to represent the direction 阅读全文
posted @ 2013-07-17 13:49 freeneng 阅读(157) 评论(0) 推荐(0) 编辑

2013年7月16日

摘要: Problem:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra m 阅读全文
posted @ 2013-07-16 11:04 freeneng 阅读(165) 评论(0) 推荐(0) 编辑
摘要: Problem:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Analysis:Please reference the answer on stackoverflow.http://stackoverflow.com/questions/3488691/how-to-rotate-a-matrix-90-degrees-without-using-any-extra-spaceT 阅读全文
posted @ 2013-07-16 09:45 freeneng 阅读(208) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 11 下一页

导航