问题描述:
Determine whether an integer is a palindrome. Do this without extra space.
基本思路:
考虑到回文的特点,根据给定数字获得与给定数字低位高位反序的数字。如果是回文数,则两数想等;否则不等。(即使反序数字溢出,也可的到正确结果)
代码:
bool isPalindrome(int x) { //...
分类:
其他好文 时间:
2014-12-04 20:04:19
阅读次数:
159
SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数; SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') space from dual; A A ZERO SPACE --------- -----.....
分类:
数据库 时间:
2014-12-04 17:09:16
阅读次数:
243
多行缩进(减少缩进):tab/shift+tab复制行:Ctrl+Alt+方向键'↓'删除行:Ctrl+d自动完成:Alt+/注释:Ctrl+/窗口最大小:Ctrl+m1 几个最重要的快捷键代码助手:Ctrl+Space(简体中文操作系统是Alt+/)快速修正:Ctrl+1单词补全:Alt+/打开外...
分类:
系统相关 时间:
2014-12-04 11:47:53
阅读次数:
297
一、单行文本溢出显示省略号(...)
设置块元素的宽和高,然后使用三个属性(缺一不可)控制
overflow: hidden;
text-overflow:ellipsis;
white-space:nowrap;
Demo如下:
效果如下:
二、多行文本溢出显示省略号(...)
可以使用以下四个属性来控制:
overflow : ...
分类:
其他好文 时间:
2014-12-04 10:18:04
阅读次数:
116
Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe...
分类:
其他好文 时间:
2014-12-04 00:46:14
阅读次数:
164
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?使用双指针fast和slow,fast每次走两步,slow每次走一步,如果fast追...
分类:
其他好文 时间:
2014-12-03 23:04:47
阅读次数:
287
preface/prehight:topic: Storage(share fileSystem(可共享文件系统,Access I/O existence bottleNeck,access read/write space slowly),BSD(block storage device,file...
分类:
其他好文 时间:
2014-12-03 22:48:58
阅读次数:
116
题目
Sort a linked list in O(n log n)
time using constant space complexity.
解答
O(nlogn)时间复杂度的排序有快排、堆排、归并,一般双向链表用快排、单向链表用归并,堆排两种都可以,以下使用归并排序:
/**
* Definition for singly-linked list.
* class Li...
分类:
其他好文 时间:
2014-12-03 21:32:25
阅读次数:
138
一、原题
Sort List
Sort a linked list in O(n log n)
time using constant space complexity.
二、分析
快速排序和归并排序的时间复杂度是O(nlogn)。如果使用归并排序,在使用链表的情况下,不需要重新申请空间存放排序后的数组,可以做到空间复杂度数O(1)。我在这里使用归并排序来排序链表...
分类:
其他好文 时间:
2014-12-03 21:28:07
阅读次数:
112
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
分类:
其他好文 时间:
2014-12-03 21:14:01
阅读次数:
198