comparator leetcode arrays sort

LeetCode C++:HashTable篇

1、Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume tha ......
HashTable LeetCode

leetcode 21. 合并两个有序链表

## 直接合并即可 这道题是简单题,直接合并即可 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int ......
leetcode 两个 21

[LeetCode] 1071. Greatest Common Divisor of Strings

For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times). Given two string ......
LeetCode Greatest Divisor Strings Common

[LeetCode] 1186. Maximum Subarray Sum with One Deletion

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, y ......
LeetCode Deletion Subarray Maximum 1186

[LeetCode] 2462. Total Cost to Hire K Workers

You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. W ......
LeetCode Workers Total 2462 Cost

关于python中numpy 的array二维数组

1、如何删除某一行、某一列 简单的例子: Original=np.array([[1,2,7,4], [7,5,1,4], [7,8,11,9], [11,3,17,2]])如下都将使用该二维数组进行示例删除某一行就是np.delete(Original,1,axis=0)想要删除某一列最简单的就是 ......
数组 python numpy array

LeetCode —— 滑动窗口

904. 水果成篮 用一个 Map 记录当前窗口的情况: key - 水果种类数 value - 这个水果种类在当前滑动窗口里出现的次数 维持一个 left 指针到 right 指针的滑动窗口 每次 right 右移一位,将新加入窗口的 fruits[right] 这个种类放到 map 里,并将该种 ......
LeetCode

[LeetCode] 2485. Find the Pivot Integer

Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements bet ......
LeetCode Integer Pivot 2485 Find

sort函数

在平常的排序过程中我么或许常常会犯难,遇到普通的数组或许还好,但是像结构体这样的数据多了难免会有些麻烦, 我查阅资料之后找到了一个函数这个函数是库里面自带的只需要头文件#include<algorithm> 下面讲讲详细用法,首先sort(a,a+n,cmp)它里面有三个变量 a代表我们的结构体的简 ......
函数 sort

【C/C++】排序函数sort()(基本数据类型&结构体排序)

库: #include<algorithm> sort函数原型(简化,能用就行): /* a和a+n是地址 对区间[a,a+n)中的元素进行排序,默认从小到大 可用cmp函数控制排序规则 */ sort(a,a+n,cmp){} 1.基本数据类型-修改排序规则-cmp函数 #include<iost ......
函数 类型 结构 数据 sort

LeetCode 128. 最长连续序列

* 为什么这题我都不会,脑袋有点累,状态真差 ``` class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(),nums.end());//记录数字是否出现过 int re ......
序列 LeetCode 128

Arrays.asList()与Collections.unmodifiableList()

# java.util.Arrays#asList 返回的是在Arrays实现的ArrayList, ``` java private static class ArrayList extends AbstractList implements RandomAccess, java.io.Seria ......
unmodifiableList Collections Arrays asList

Merge Sorted Array

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in num ......
Sorted Merge Array

leetcode-前缀和数组&差分数组

前缀和数组: 前缀和技巧适用于快速、频繁地计算一个索引区间内的元素之和。(仅仅适用于原数组不变的情况,如果原数组经常修改,则需要考虑差分数组。) 看两道例题就清楚了: 1. 303. 区域和检索 - 数组不可变 - 力扣(LeetCode) 由于要频繁计算某个区间内的元素之和,暴力解法复杂度太大,显 ......
数组 前缀 leetcode amp

Faster sorting algorithms discovered using deep reinforcement learning

## 摘要: - `AlphaDev`模型优化排序算法,将排序算法提速70%。通过强化学习,AlphaDev发现了更加有效的算法,直接超越了科学家和工程师们几十年来的精心打磨。现在,新的算法已经成为两个标准C++编码库的一部分,每天都会被全球的程序员使用数万亿次。 ## 介绍 - 优化目标为排序算法 ......

LeetCode 周赛 351(2023/06/25)T2 有点意思

> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。** - 往期回顾:[LeetCode 单周赛第 348 场 · 数 ......
LeetCode 意思 2023 351 06

LeetCode 双周赛 107(2023/06/24)滑动窗口与离散化

> **本文已收录到 [AndroidFamily](https://github.com/pengxurui/AndroidFamily),技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。** - 往期回顾:[LeetCode 单周赛第 348 场 · 数 ......
LeetCode 2023 107 06 24

【Leetcode每日一题】判定是否互为字符重排

题目 思路 思路比较简单,作两个长度为26的数组,用来存储对应序列字母的个数。遍历完成后对比两个数组,根据是否存在相同序列位置字母个数不一样的情况来确定两个字符串是否都是由相同的字母构成的。 值得一提的是在一开始我忽略了“字母个数必须相同”这一条件。 代码 impl Solution { pub f ......
字符 Leetcode

C++面试八股文:std::array如何实现编译器排序?

某日二师兄参加XXX科技公司的C++工程师开发岗位第25面: > 面试官:`array`熟悉吗? > > 二师兄:你说的是原生数组还是`std::array`? > > 面试官:你觉得两者有什么区别? > > 二师兄:区别不是很大,原生数组(非动态数组)和std::array都在栈上开辟空间,初始化 ......
八股文 八股 编译器 array std

二叉树-快排-leetcode912

给你一个整数数组 nums,请你将该数组升序排列。 示例 1: 输入:nums = [5,2,3,1] 输出:[1,2,3,5] 示例 2: 输入:nums = [5,1,1,2,0,0] 输出:[0,0,1,1,2,5] 提示: 1 = hi) { return; } // 对 nums[lo.. ......
leetcode 912

[Leetcode] 0026. 删除有序数组中的重复项

# [26. 删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array) 点击上方,跳转至Leetcode ## 题目描述 给你一个 升序排列 的数组 nums ,请你 原地 删除重复出现的元素,使每个 ......
数组 Leetcode 0026

[Leetcode] 0026.删除有序数组中的重复项

# [26. 删除有序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array) [English Version](/solution/0000-0099/0026.Remove%20Duplicates%2 ......
数组 Leetcode 0026

[Leetcode] 0021. 合并两个有序链表

# [21. 合并两个有序链表](https://leetcode.cn/problems/merge-two-sorted-lists) 点击上方,跳转至Leetcode ## 题目描述 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: ......
Leetcode 两个 0021

【LeetCode摩尔投票】有趣的简单题:数组中出现次数超过一半的数字

### 数组中出现次数超过一半的数字 https://leetcode.cn/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/ 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。 你可以假设数组是非 ......
数组 LeetCode 次数 数字

[leetcode]114. 二叉树展开为链表

总结:怎样写递归函数?关键是把递归函数的功能定义清楚,并在递归函数体中使用自身来做事,此时不要关注递归函数执行的细节。也就是写高层级代码的时候不要关注低层级的事情,这就叫抽象。关注也没有用,想不清楚的。 1 class Solution { 2 public void flatten(TreeNod ......
leetcode 114

LeetCode/子集、组合

###一 . 子集 给你一个整数数组 nums ,数组中的元素 互不相同,返回该数组所有可能的子集 #### 1. 回溯法 对每个数做选择,放入当前位,同时固定访问顺序,只访问下标更大的数,避免重复 回溯法 ``` class Solution { public: vector> res; vect ......
子集 LeetCode

leetcode5最:长回文子串

动态规划: 1个回文串,两边加上同样的字符,也是回文串。这是一个性质,之后要用。 对于一大串字符,从1长度的子串开始判断。 1个长度的子串,肯定回文;如果这个子串两边加上同样的字符,长度变成了3,少了一次判断。 因此还要加上,判断2长度的子串是不是回文。 之后才会判断3长度的子串是不是回文。 以此类 ......
回文 leetcode5 leetcode

LeetCode/特别的排列

给你一个下标从 0 开始的整数数组 nums ,它包含 n 个 互不相同 的正整数。如果 nums 的一个排列满足以下条件,我们称它是一个特别的排列: 对于 0 & nums) { int mod = 1e9+7; int m = nums.size(); int memo[m][m f = [&] ......
LeetCode

做leetcode算法题的一些感受

leetcode题目做了34道了,写下目前的感受,不一定对,需要经常修改内容。 1、代码是怎么写出来的?不是一下子写出来的,是逐步填充,逐步具体的。一句话,写代码也要看到历史和现状,现状不是突然出现的,是有发展历史的。不是从1直接就到10了,而是从1->2->3,逐步递进,最后到10。写代码总要写第 ......
算法 leetcode

Leetcode: Arrays.sort() - comparator

Arrays.sort(points,(o1,o2)->{ if(o1[1] == o2[1]) return 0; if(o1[1] < o2[1]) return -1; return 1; }) 根据dp[1]进行升序排列,O(NlogN) ......
comparator Leetcode Arrays sort