摘要: 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 ≤m≤n≤ length of list.Summary: First writes down the reverse parts (m to n) 阅读全文
posted @ 2013-10-29 14:41 假日笛声 阅读(207) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cases.Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return&quo 阅读全文
posted @ 2013-10-29 12:50 假日笛声 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Summary: To sort and compare strings, using map to record distinct strings. 1 class Solution { 2 public: 3 vector anagrams(vector &strs) { 4 vector result; 5 map str_m... 阅读全文
posted @ 2013-10-29 11:35 假日笛声 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].Notes: recursive, in place. 1 class Solution { 2 public: 3 vector > permute(vector &num) { 7 int size = num.size(); 8 ... 阅读全文
posted @ 2013-10-29 11:00 假日笛声 阅读(159) 评论(0) 推荐(0) 编辑