随笔分类 - 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...
阅读全文
摘要: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个字符调用一...
阅读全文
摘要: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.旋转链表:...
阅读全文
摘要:Sort a linked list inO(nlogn) time using constant space complexity.链表排序。要达到nlogn的时间复杂度,能想到归并排序与快速排序。这里采用归并排序: 1 /** 2 * Definition for singly-linked ...
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space.自己之前的想法是先转换成字符串模式,然后首尾同时开始遍历比较,如果不同则非回文。但是这个要求是不能有额外的空间。所以在网上查找了其他算法,看到是太惊叹了...
阅读全文

浙公网安备 33010602011771号