摘要: 开始想的是计数排序,但超时,如[2,999999999]这样的样例,记录数组太长,有用的占比太少。后看官方思路,用n+1(n为原数组元素个数)个桶去筛元素,每个桶能放的元素大小范围固定,即下面代码中的step,处理完后再扫描一遍当前桶最大和后继桶最小值的差,取最大差值为结果。至于为什么要n+1个桶, 阅读全文
posted @ 2019-07-13 21:41 NeoZy 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 参考 https://www.cnblogs.com/jclian91/p/9151120.html 1.暴力算法 O(n^2) def maximum_subarray_1(nums): siz=len(nums) res=0 for i in range(siz): sum=0 for j in 阅读全文
posted @ 2019-07-07 15:11 NeoZy 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 放假没事干,复习复习,有空再用python写一遍 #include<iostream> #include<math.h> #include<Windows.h> #include<vector> #include<time.h> using namespace std; //冒泡排序 void Bu 阅读全文
posted @ 2019-07-05 00:51 NeoZy 阅读(118) 评论(0) 推荐(0) 编辑
摘要: python 前面加个dummy节点,这样就不用考虑头节点的更新问题了 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None 阅读全文
posted @ 2019-07-02 19:10 NeoZy 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 俺的: class Solution: def removeDuplicates(self, nums: List[int]) -> int: if(len(nums)==0): return 0 i=0 while i<len(nums): s=i while i<len(nums) and nu 阅读全文
posted @ 2019-07-02 18:22 NeoZy 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 176编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。 select IFNULL((SELECT distinct salary from employee order by salary desc limit 1,1),NULL)AS SECONDHIGHES 阅读全文
posted @ 2019-06-11 17:07 NeoZy 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 1 3.7往后iterable 、iterator包都包含在collections.abc中了,记录一下 from collections.abc import Iterable,Iterator print(isinstance((),Iterable)) 2 int进制转换:hex() int( 阅读全文
posted @ 2019-06-06 15:31 NeoZy 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1、distinct关键字只在select单个属性时有效果,多个属性无效。 select distinct a,b from A; //若有两个元组分别为(a=1,b=1)和(a=1,b=2) //该次选择是会把这两条元组都筛选出来的 2、exists关键字 score表有s_id,c_id,sco 阅读全文
posted @ 2019-06-04 13:30 NeoZy 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 题目: 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合。 示例: 输入: n = 4, k = 2输出:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],] 解答: 回溯算法 Python: 1 class Solution: 2 d 阅读全文
posted @ 2019-05-22 19:53 NeoZy 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 参考: https://www.cnblogs.com/linxiyue/p/3659448.html?utm_source=tuicool&utm_medium=referral class Node: def __init__(self,key): self.key=key self.left= 阅读全文
posted @ 2019-05-07 17:03 NeoZy 阅读(212) 评论(0) 推荐(0) 编辑