最近需要自定义排序序列,一直一筹莫展。然后发现,利用 sort()?或 sorted()?的 key?即可实现。 ????示例如下: def?sort_key(obj):
????sorted_list?=?[4,?2,?5,?9,?7,?8,?1,?3,?...
分类:
编程语言 时间:
2014-11-30 18:51:12
阅读次数:
165
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row...
分类:
其他好文 时间:
2014-11-30 16:56:56
阅读次数:
120
把一个有序链表构成成平衡二叉树。和上一题有一点像。思路一:将有序链表存在一个数组里。然后根据每次访问中间节点当做根节点递归左右子树节点即可。代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val;...
分类:
其他好文 时间:
2014-11-29 22:53:04
阅读次数:
271
利用更有序数组,构造平衡二叉树。思路,递归,每次中间节点为根节点,然后递归获得左右子树。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *...
分类:
其他好文 时间:
2014-11-29 22:52:43
阅读次数:
239
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.这题思路参照Conve...
分类:
其他好文 时间:
2014-11-29 20:07:35
阅读次数:
178
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.The first integer of each...
分类:
编程语言 时间:
2014-11-29 17:41:48
阅读次数:
176
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...
分类:
其他好文 时间:
2014-11-29 11:38:36
阅读次数:
128
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its inde...
分类:
其他好文 时间:
2014-11-29 07:07:11
阅读次数:
194
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Solution:...
分类:
其他好文 时间:
2014-11-29 07:03:53
阅读次数:
194
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume that A has enough space (size that is greater or equa...
分类:
其他好文 时间:
2014-11-29 07:00:12
阅读次数:
193