摘要: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2016-11-27 10:05 lettuan 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Brute Force算法,时间复杂度 O(mn 阅读全文
posted @ 2016-11-27 09:32 lettuan 阅读(132) 评论(0) 推荐(0) 编辑
摘要: Reverse a singly linked list.一般,reverse list, reverse list by pair 等都需要三个指针,cur = head, prev, 和当前的下一个temp. 这里在head到达边界之后,还会再走一步,所以对应新的表头的是prev. 1 class Solution(object): 2 def reverseList(self,... 阅读全文
posted @ 2016-11-27 09:26 lettuan 阅读(194) 评论(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-11-27 09:24 lettuan 阅读(145) 评论(0) 推荐(0) 编辑
摘要: You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you nee 阅读全文
posted @ 2016-11-26 15:38 lettuan 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Invert a binary tree. to 非递归的话,需要一个queue辅助。 阅读全文
posted @ 2016-11-21 10:55 lettuan 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 本题用brute force超时。可以用DP,也可以不用。 dp[i][j] 代表 以(i,j)为右下角正方形的边长。 阅读全文
posted @ 2016-11-21 10:49 lettuan 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XOR的特性, X^0 = X, X^X = 0, 并且XOR满足交换律。 single number 阅读全文
posted @ 2016-11-21 04:46 lettuan 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 求次数的问题一般用DP 阅读全文
posted @ 2016-11-20 15:07 lettuan 阅读(179) 评论(0) 推荐(0) 编辑
摘要: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For exampl 阅读全文
posted @ 2016-11-19 07:41 lettuan 阅读(169) 评论(0) 推荐(0) 编辑