随笔分类 -  Leetcode

摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2014-11-21 15:16 Craze_lee 阅读(222) 评论(0) 推荐(0)
摘要:Given this linked list:1->2->3->4->5Fork= 2, you should return:2->1->4->3->5Fork= 3, you should return:3->2->1->4->5思路:一开始是想要动态规划的方式,即写一个反转函数,每K个字符调用一... 阅读全文
posted @ 2014-10-27 10:25 Craze_lee 阅读(171) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.旋转链表:... 阅读全文
posted @ 2014-10-26 10:21 Craze_lee 阅读(110) 评论(0) 推荐(0)
摘要:Sort a linked list inO(nlogn) time using constant space complexity.链表排序。要达到nlogn的时间复杂度,能想到归并排序与快速排序。这里采用归并排序: 1 /** 2 * Definition for singly-linked ... 阅读全文
posted @ 2014-10-26 09:30 Craze_lee 阅读(129) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space.自己之前的想法是先转换成字符串模式,然后首尾同时开始遍历比较,如果不同则非回文。但是这个要求是不能有额外的空间。所以在网上查找了其他算法,看到是太惊叹了... 阅读全文
posted @ 2014-10-21 11:06 Craze_lee 阅读(253) 评论(0) 推荐(0)