摘要: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo 阅读全文
posted @ 2016-12-24 12:53 wilderness 阅读(188) 评论(0) 推荐(0)
摘要: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your a 阅读全文
posted @ 2016-12-24 12:29 wilderness 阅读(112) 评论(0) 推荐(0)
摘要: 八皇后问题: 把N个皇后,放在N*N的棋盘上面,从第一行往下放,每个皇后占一行,同时,每个皇后不能处在同一列,对角线上,有多少种放置方法。 思路: 典型的回溯问题: 1.当要放置最后一个皇后时候,默认前N-1个皇后已经全部放置好了,那么验证在第N行上的每个位置是否可行,即是否与之前的皇后在同一列或者 阅读全文
posted @ 2016-12-23 23:46 wilderness 阅读(386) 评论(0) 推荐(0)
摘要: 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. 题意:合并两个已 阅读全文
posted @ 2016-12-23 18:39 wilderness 阅读(191) 评论(0) 推荐(0)
摘要: Given a linked list, remove the nth node from the end of list and return its head. For example, 题意:给出一个链表,删除倒数第n个节点 刚在书上见过这个题,思路是用双指针,p1,p2,先让p2走n步,然后 阅读全文
posted @ 2016-12-23 17:56 wilderness 阅读(158) 评论(0) 推荐(0)
摘要: l=[1, 2, 3, 4, 5, 6] 如果l求和,毫无疑问可以使用递归,比如可以这样: 如果我们想把l中的所有子列表裂解开,这种方法行不行。。。?比如可以这样 方法1: 如果使用生成器的话: 方法2 可以看到方法2看起来简单了很多,但是方2都有一个问题,如果有一个列表是这样的 那么方法2还可行吗 阅读全文
posted @ 2016-12-23 15:23 wilderness 阅读(1004) 评论(0) 推荐(0)
摘要: Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文
posted @ 2016-12-22 23:59 wilderness 阅读(161) 评论(0) 推荐(0)
摘要: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2016-12-22 23:04 wilderness 阅读(123) 评论(0) 推荐(0)
摘要: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of 阅读全文
posted @ 2016-12-22 17:00 wilderness 阅读(164) 评论(0) 推荐(0)
摘要: Write a function to find the longest common prefix string amongst an array of strings. 题意:找出所给几个字符串的相同前缀 思路:用第一个字符串和之后的所有字符串进行对比,标示出相同字符串的超尾指针就行 ps:通过 阅读全文
posted @ 2016-12-22 13:28 wilderness 阅读(202) 评论(0) 推荐(0)