comparator leetcode arrays sort
7-009-(LeetCode- 309) 最佳买卖股票时机含冷冻期
1. 题目 读题 考查点 2. 解法 思路 代码逻辑 具体实现 1 1 3. 总结 ......
LeetCode/移动石子直到连续
###1. 移动石子直到连续(三个石子) class Solution { public: vector<int> numMovesStones(int a, int b, int c) { int x = min({a, b, c}); int z = max({a, b, c}); int y ......
B. Sort with Step
题意:
给定一个长度为n的数组,任意两个数如果满足i-j的绝对值等于k则可以互相交换,若不能通过此操作实现数组排序,则需要使用次数来强制交换,次数小于等于1输出次数,否则输出-1.
分析:
最优情况下,找出需要操作的数的数量然后两两交换是次数最少的。
代码: ......
[LeetCode] 1033. Moving Stones Until Consecutive
There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones. In one move, you p ......
Python 希尔排序(Shell Sort)原理以及应用
##希尔排序的原理: 希尔排序是把记录按下标的一定增量分组,对每组使用直接插入排序算法排序; 随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止。 希尔排序的原理是将待排序的序列按照一定间隔分成若干个子序列,对每个子序列使用插入排序进行排序,缩小间隔后再次进 ......
leetcode_D10_136只出现一次的数字
1.题目 2.解一 leetcode官方解法,主要用到了两个知识:第一个是reduce函数,需要注意的是在python3中,需要 通过“ from functools import reduce ”从模块中调用该函数;第二个知识是位运算中的异或运算,主要有以下计算法则。 有了这两个补充知识,该题目就 ......
2023-04-28 LeetCode精选题目20道附我的Java实现
LeetCode精选题目20道 1.56.合并区间 贪心 给出一个区间的集合,请合并所有重叠的区间。 示例 1: 输入: intervals = [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] ......
3、题目:Feedback in concept development: Comparing design disciplines
期刊信息 (1)作者:Yilmaz, Seda. (2)期刊:Design Studies, 2016, 45: 137-158 (3)DOI:10.1016/j.destud.2015.12.008 (4)ISSN:0142-694X (5)IF:3.853 (Q2) 研究背景 设计反馈是促进学生 ......
pop 出栈,sorted临时排序,容器类型的数据,zip函数
divmod(a, b)返回一对商和余数,结果和 (a // b, a % b) 一致 字典是Python 中唯一的映射类型。 Python的源文件以"py"为扩展名,有python.exe解释运行,可在控制台下运行。"pyw"是图形开发用户接口(GUI)文件的扩展名,作为桌面应用程序,这种文件用于 ......
C语言刷leetcode——并查集
概述 https://leetcode.cn/problems/number-of-provinces/solution/python-duo-tu-xiang-jie-bing-cha-ji-by-m-vjdr/ 基本概念 并查集是一种数据结构 并查集这三个字,一个字代表一个意思。 并(Union ......
vscode-leetcode
vscode 里写 leetcode 需要的插件xavier-cai.vscode-leetcode-cpp-debug, leetcode.vscode-leetcode LeetCode C++ Debugger.Delete Temporary Contents置为false ctrl+shi ......
LeetCode 241 为运算表达式设计优先级
LeetCode | 241.为运算表达式设计优先级 给你一个由数字和运算符组成的字符串 expression ,按不同优先级组合数字和运算符,计算并返回所有可能组合的结果。你可以 按任意顺序 返回答案。 生成的测试用例满足其对应输出值符合 32 位整数范围,不同结果的数量不超过 104 。 示例 ......
List集合排序 sort方法
List集合排序 sort方法: public static void sort(List list) :将集合中元素按照默认规则排序。 public static void sort(List list,Comparator<? super T> ) :将集合中元素按照指定规则排 序。 sort方 ......
【二分查找】LeetCode 153. 寻找旋转排序数组中的最小值
题目链接 153. 寻找旋转排序数组中的最小值 思路 首先分析一下旋转数组可能有的状态: 左 < 中 < 右,此时最小值肯定在左边,应当收缩右边界 左 < 中,中 > 右,此时最小值肯定在右半段,应当收缩左边界 左 > 中,中 < 右,此时最小值肯定在左半段,应当收缩右边界 分析这三种状态可以发现, ......
[LeetCode] 1031. Maximum Sum of Two Non-Overlapping Subarrays
Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths ......
LeetCode 双指针
15. 三数之和 (为0) 下标不能是重复的,必定右 i<l<r 1、先对数组排序(从小到大) 2、外层 i 遍历 如果 nums[i] > 0 ,整个 nums[] 后面的必定无法有三元组为0(排过序了,后面的 nums[l] nums[r] 都会大于0)。break。 如果 nums[i] = ......