- 博客(10)
- 收藏
- 关注
原创 python intertools模块使用
Reshape the matrix: 给定一个二维矩阵,两个正整数r, c,将它reshape为r*c,如果不能reshape则返回原矩阵.Input: nums = [[1,2], [3,4]]r = 1, c = 4Output: [[1,2,3,4]]Explanation:The row-traversing of nums is [1,2,3,4]. The ne...
2018-08-29 15:28:31
3837
原创 数据结构: hashtable
自己学习总结使用,文末附参考链接。Hashtable原理 哈希表(hash table, 也叫散列表),是种根据关键码值(Key value)而直接进行访问数据结构,它可以提供快速的插入操作和查找操作。也就是说,它通过把关键字值映射到一个位置来访问记录,以加快查找的速度。这个映射函数称为哈希函数(也称为散列函数),映射过程称为哈希化,存放记录的数组叫做散列表。哈希表最大的优点,就是把...
2018-07-13 20:15:29
892
原创 leetcode:Array Nesting
Array NestingA zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule b...
2018-05-21 16:32:54
123
原创 leetcode:Product of Array Except Self
Product of Array Except SelfGiven an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Input: [1,...
2018-05-20 21:39:06
87
原创 leetcode:Beautiful Arrangement II
Beautiful Arrangement IIGiven two integers n and k you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list ...
2018-05-18 16:06:00
114
原创 leetcode:Find All Duplicates in an Array
Find All Duplicates in an ArrayGiven an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Cou...
2018-05-16 16:04:19
129
原创 leetcode:Non-decreasing Array
Non-decreasing Array改变序列中至多一个数,使之变成不增序列array[i] <= array[i + 1]def nondecreasing(nums): one, two = nums[:], nums[:] for i in range(len(nums) - 1): if nums[i] > nums[i + 1]: ...
2018-05-16 14:46:56
102
原创 leetcode:Rotate Array
Rotate ArrayInput: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,4,5,6]rotate 2 steps to the right: [6,7,1,2,3,4,5]rotate 3 steps to the right...
2018-05-15 16:39:27
103
原创 leetcode:Third Maximum Number
Third Maximum Number在非空整数数组中找到倒数第三大的数;如果长度小于三,返回最大的数;第三个最大不同数字。def thirdMax(nums): v = [float('-inf'), float('-inf'), float('-inf')] for num in nums: if num not in v: if nu...
2018-05-15 15:32:31
92
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人