思路:
大概思路就是找出K个结点的起始位置和并将这K 个结点采用头插法的方式依次插入到这K个结点开始位置的前面一个位置之后,就可以了。
思路倒是很简单,但是指针所指的位置的捉摸是有点麻烦的,还有就是我竟然没有把创建的头节点和整个链表给链接起来。anyway,还是把这道题目给做出来了。...
分类:
其他好文 时间:
2015-02-07 11:48:02
阅读次数:
138
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link...
分类:
其他好文 时间:
2015-02-07 09:08:17
阅读次数:
165
1 public static ListNode reverseBetween(ListNode head, int m, int n) { 2 ListNode pre=head,current=head,mPre = new ListNode(0),mNode = new L...
分类:
编程语言 时间:
2015-02-06 18:23:59
阅读次数:
141
Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string does not contain lead...
分类:
其他好文 时间:
2015-02-06 16:36:03
阅读次数:
104
前话 今天开始励志刷一下leetcode上面的题目(还好这个网站没被TG和谐)。从easy的开始,数一下差不多有40道,争取两个月搞定。题目 没想到做的第一道题目,虽然看似简单,却费了很大周折。题目如下:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -3...
分类:
其他好文 时间:
2015-02-06 14:59:15
阅读次数:
130
一、 题目
试确定一个整数是否为回文数。并不使用额外的空间。
提示:
负整数可能是回文数吗?(例如 -1)
如果你想要将整数转换成字符串,那么你注意到不能使用额外的空间的限制。
可能你尝试翻转整数,但是,如果你已经解决这个问题“逆向整型”,你要知道,颠倒整数可能会溢出的情况。那么你会如何处理这样的情况呢?
要有解决这个问题的一种更通用的方法。
二、 分析
了解题目的意思后,其实问题...
分类:
其他好文 时间:
2015-02-06 14:55:47
阅读次数:
151
<script?type="text/javascript">
<!--?one-way?linkedlist?reverse?in?javascript?-->
function?Node(value)?{
this.value?=?value;
this.next?=?null;
}
Node.prototype.setNext?=?fun...
分类:
编程语言 时间:
2015-02-04 21:58:39
阅读次数:
288
数组的逆序,只能用于数组,不能用于哈希表
function reverseTable(tab)
local tmp = {}
for i = 1, #tab do
local key = #tab
tmp[i] = table.remove(tab)
end
return tmp
end
// 示例
local t = {"one", "two", "three"}
...
分类:
编程语言 时间:
2015-02-04 21:50:25
阅读次数:
6498
思路:
这种题目,举个例子能让思路更加清晰,通过在草纸上演算可知,题目要分两种情况,m==1和m>1的情况,然后就是围绕这两种情况展开讨论,删除后面的结点,然后将后面的结点添加到前面,一次搞定,bravo!...
分类:
其他好文 时间:
2015-02-04 21:49:53
阅读次数:
215
1, 常规实现: scala> val list = List(1,2,3,4,5)
list: List[Int] = List(1, 2, 3, 4, 5)
scala> list.foldLeft(List.empty[Int])((res, cur) => cur::res)
res0: List[Int] = List(5, 4, 3, 2, 1) 2, 加上泛型...
分类:
其他好文 时间:
2015-02-04 18:59:52
阅读次数:
182