要实现数据的任意排序需要满足以下条件:每条数据有唯一的排序值,这个可以添加时取当前最大(或最小)的排序值加一(或减一)获取输入:id:要排到其他位置的数据IDtarget_id:数据被插入的目标ID 带附号形式,如'+10', '-12',数字形式,如'17'数据:sort_order:...
分类:
编程语言 时间:
2015-04-01 16:41:57
阅读次数:
123
The set [1,2,3,…,n] contains a total of n!
unique permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123""132""213""231""3...
分类:
其他好文 时间:
2015-04-01 15:22:03
阅读次数:
150
problem:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
For example,
Given the following matrix:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],...
分类:
其他好文 时间:
2015-04-01 11:26:55
阅读次数:
109
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers ...
分类:
其他好文 时间:
2015-04-01 11:25:15
阅读次数:
88
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解:递归就可以了。Java代码如下: 1 /** 2 * Definition for binary ....
分类:
其他好文 时间:
2015-04-01 00:16:07
阅读次数:
96
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
之前在Sicily做过,就是实现一个AVL树了。
struct TreeNodeNew {
int val;
TreeNodeNew *left;
Tr...
分类:
其他好文 时间:
2015-03-31 18:09:23
阅读次数:
150
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat...
分类:
其他好文 时间:
2015-03-31 17:40:27
阅读次数:
114
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat...
分类:
其他好文 时间:
2015-03-31 17:29:00
阅读次数:
100
之前的一篇笔记曾分析过,Go的map在底层是用hashmap实现的。由于高效的hash函数肯定不是对key做顺序散列的,所以,与其它语言实现的hashmap类似,在使用Go语言map过程中,key-value的插入顺序与遍历map时key的访问顺序是不相同的。熟悉hashmap的同学对这个情况应该非常清楚。
所以,本文要提到的肯定不是这个,而是一个比较让人惊奇的情况,下面开始说明。
1. 通过...
分类:
其他好文 时间:
2015-03-31 16:11:21
阅读次数:
494
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example:
Given binary tree {3,9,20,#,#,15,7},
3
/ 9 20
...
分类:
其他好文 时间:
2015-03-31 14:46:03
阅读次数:
146