![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
排序
枫流仁武
这个作者很懒,什么都没留下…
展开
-
LeetCode 164 最大间距
给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。 如果数组元素个数小于 2,则返回 0。 from typing import * class Solution: def maximumGap(self, nums: List[int]) -> int: if len(nums) < 2: return 0 max_val, min_val = max(nums), min(nums) if原创 2020-11-26 09:56:18 · 94 阅读 · 0 评论 -
LeetCode 57 插入区间
给出一个无重叠的 ,按照区间起始端点排序的区间列表。 在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。 本题可以有线性复杂度的算法,但是线性复杂度的算法需要考虑的情况很多,不如之间先排序后合并。 from typing import * class Solution: def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[i原创 2020-11-04 08:51:35 · 91 阅读 · 0 评论 -
LeetCode 215 数组中的第K个最大元素
利用快速排序的方法解决 from typing import * class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: return self.helper2(nums,0,len(nums)-1,len(nums)-k+1) def helper2(self,nums,lo,hi,k): idx=self.helper1(nums,lo,hi)原创 2020-06-29 09:38:24 · 59 阅读 · 0 评论 -
PAT 1080 Graduate Admission
按照给定规则排好序,从头到尾进行录取,注意要同时录取排名相同的所有学生.每个学校录取的人数可能超过给定的上限. 这种题需要静下心来慢慢做,不能浮躁 #include <iostream> #include <vector> #include <algorithm> #include <map> #include <cstring> ...原创 2019-06-10 16:59:42 · 84 阅读 · 0 评论 -
PAT 1075 PAT Judge
这道题细节贼多...需要注意很多点 不能用cout,会超时 排名是根据总分排序,输出要考虑总分,达到满分题目个数,以及id编号 注意编译错误和没有提交题目,可以用不同的数字来表示 消极做题的没有资格输出(没有提交过或者编译没有通过过) 给出代码: #include <iostream> #include<vector> #include <cstring&...原创 2019-06-18 17:56:23 · 93 阅读 · 0 评论 -
PAT 1113 Integer Set Partition
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { // std::cout << "Hello, World!" << std::endl; int N; cin>>...原创 2019-06-18 18:46:18 · 64 阅读 · 0 评论 -
PAT 1085 Perfect Sequence
二分法解决: 二分法的题有的时候真的很迷... 起初最后一个测试点总也过不去,加了一行之后就成功了~ 至于为什么加那一行我也不清楚了... #include <algorithm> #include <iostream> #include <vector> typedef long long LL; using namespace std; int B...原创 2019-07-10 14:14:55 · 106 阅读 · 0 评论 -
PAT 1098 Insertion or Heap Sort
According to Wikipedia: Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2019-07-07 12:26:50 · 91 阅读 · 0 评论