vector sort std

Remove Duplicates from Sorted List

Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. **Examp ......
Duplicates Remove Sorted List from

C++17之std::any

一般来说,c++是一种具有类型绑定和类型安全性的语言。值对象声明为具有特定类型,该类型定义哪些操作是可能的以及它们的行为方式。值对象不能改变它们的类型。 std: any是一种值类型,它能够更改其类型,同时仍然具有类型安全性。也就是说,对象可以保存任意类型的值,但是它们知道当前保存的值是哪种类型。在 ......
std any 17

C++ 计时方法 std::chrono

计时的作用:测试某一段代码的运行时间,时间越短,则性能相对越高。 C++11 标准的”最佳计时方法“的代码: 1 #include <chrono> 2 using namespace std; 3 using namespace chrono; 4 5 auto start = system_cl ......
方法 chrono std

C++ std::move 的一些问题

看 SO 上有一个比较奇怪的问题, When does an rvalue reference result in a move vs copy constructor and why? 问题代码: ClassX c = std::move(object_c); // Invokes move co ......
问题 move std

C++ std::chrono的时钟Clock

std::chrono是C++11引入的日期时间处理库,其中包含3种时钟:system_clock,steady_clock,high_resolution_clock。近来需要使用高精度时间,很自然想到使用high_resolution_clock,然而使用后发现并非预期的得到自1970/1/1零 ......
时钟 chrono Clock std

20230407 Arrays.sort

分析以下方法: - Arrays#sort(int[]) - Arrays#sort(Object[] a) ## DualPivotQuicksort - Arrays#sort(int[]) 使用 DualPivotQuicksort - Dual-Pivot Quicksort 是一种快速排序 ......
20230407 Arrays sort

std::thread 六:多线程&单例类

为了避免单例类在多线程中重复的创建,下面提供了两种解决方法: 1.互斥锁+双重检查 2.std::call_once() 方法一:互斥锁+双重检查 #include <iostream> #include <thread> #include <mutex> #include <list> using ......
线程 thread std amp

std::thread 四:异步(async)

*:如果 std::async 中传递参数 std::lunnch::deferred ,就需要等待调用 get() 或者 wait() 才会执行,并且代码非子线程运行,而是在主线程中执行 #include <iostream> #include <thread> #include <mutex> ......
thread async std

std::thread 五:打包任务(packaged_task)

#include <iostream> #include <thread> #include <mutex> #include <list> #include <future> using namespace std; int myThread(int num) { cout << "myThrea ......
packaged_task packaged 任务 thread task

std::thread 三:条件变量(condition_variable())

condition_variable 、 wait 、 notify_one 、 notify_all *:notify_one:通知(唤醒)一个线程 *:notify_all:通知(唤醒)多个线程 #include <iostream> #include <thread> #include <mu ......

std::thread 二:互斥量(带超时的互斥量 timed_mutex())

timed_mutex 、 try_lock_for 、 try_lock_until #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { publ ......
timed_mutex thread mutex timed std

std::thread 二:互斥量(多个互斥量的解决方法)

// *:这里的lock是函数模板,最少传两个互斥量 // 第一种,使用 lock 和 unlock std::mutex m_mutex1; std::mutex m_mutex2; std::lock(m_mutex1, m_mutex2); m_mutex1.unlock(); m_mutex ......
多个 方法 thread std

std::thread 二:互斥量(lock() & unlock())

mutex 互斥量的作用是保护共享数据 *:有 lock() 就一定要有 unlock() #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { pu ......
thread unlock lock std amp

std::thread 二:互斥量(lock_guard())

*:使用 lock_guard 后,就不可以使用 lock() 和 unlock() *:lock_guard 和智能指针一样,会自动解锁 #include <iostream> #include <thread> #include <mutex> #include <list> using nam ......
lock_guard thread guard lock std

std::thread 一:创建线程的三种方式

前言: #include <thread> thread.join() // 阻塞 thread.detach() // 非阻塞 thread.joinable() // bool,判断线程是否支持join或者detach 正文: 创建线程有三种方式,分别是:使用函数来创建线程、使用自定义的类来创建 ......
线程 方式 thread std

std::string 拼接字符串

#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string a = "123"; stringstream b; b << 123 << "456" << 789 ......
字符串 字符 string std

C++面试八股文:std::string是如何实现的?

某日二师兄参加XXX科技公司的C++工程师开发岗位第18面: > 面试官:`std::string`用过吧? > > 二师兄:当然用过(废话,C++程序员就没有没用过`std::string`的)。 > > 面试官:`std::string("hello")+"world"`、`"hello"+st ......
八股文 八股 string std

STL vector容器存储键值对

在阅读tvm源码时,发现了一个挺有意思的代码: ```C++ std::vector> update; ``` vector容器里竟然存储的是键值对,amazing啊!!!还是第一次遇到这种写法的,这与直接写成map有啥不一样呢? 首先,这两种方式都可以用于存储键值对,只是它们具有不同的特性和实用场 ......
容器 vector STL

.Net7发现System.Numerics.Vector矢量化的一个bug,Issues给了dotnet团队

因为前几天做.Net7的矢量化性能优化,发现了一个bug。在类System.Numerics.Vector里面的成员变量IsHardwareAccelerated。但是实际上不确定这个bug是visual studio 2022的还是System.Numerics.Vector库的,个人认为应该是前 ......
矢量化 矢量 Numerics 团队 Issues

【LeetCode哈希表】前k个高频词,利用哈希表+vector进行排序操作

### 前k个高频词 https://leetcode.cn/problems/top-k-frequent-words/ 给定一个单词列表 words 和一个整数 k ,返回前 k 个出现次数最多的单词。 返回的答案应该按单词出现频率由高到低排序。如果不同的单词有相同出现频率, 按字典顺序 排序。 ......
LeetCode vector

c++多线程 std::async std::future

c++标准库中对线程操作有完善的封装,其中最常用到的如std::thread, std::async。 EffectiveModernCpp中指出,应尽量使用std::async即基于任务的编程而非基于线程的编程。std::thread在前面的文章有提到过,此处仅对std::async作以记录。 正 ......
线程 std future async

CF1830E Bully Sort

[题面传送门](https://www.luogu.com.cn/problem/CF1830E) 我们考虑选中的 $i$,这个位置一定是 $p_i>i$,它想要往后走。而和它交换的 $j$,因为 $\leq i$ 的有 $i$ 个数,现在第 $i$ 个位置已经被 $p_i$ 占据了,所以 $\le ......
1830E Bully 1830 Sort CF

leetcode735行星碰撞vector模拟栈操作

vector的基本操作: vector<int >v; v.back();//获取尾部数据 v.front();//获取首部数据 v.push_back(3);//在尾部加入数据3 v.pop_back();//弹出尾部数据 首先只有前一个行星向右走,后一个行星向左走才可能相撞。也就是一正一负的组合 ......
行星 leetcode vector 735

Qt error: C7525: 内联变量至少需要 “/std:c++17“

碰到这种错误,只需要在Qt中配置C++17即可解决 打开该项目中的xxx.pro文件,然后如下图中红色方框中配置:CONFIG += c++17 ......
变量 C7525 error 7525 std

python高阶函数filter、sorted学习笔记

# filter Python内建的filter()函数用于过滤序列。 和map()类似,filter()也接收一个函数和一个序列。和map()不同的是,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素。 e.g在一个list中,删掉偶数, ......
高阶 函数 笔记 python filter

std::package_task bind.lambda,thread,future

#include <atomic> #include <chrono> #include <cmath> #include <condition_variable> #include <cstddef> #include <forward_list> #include <fstream> #incl ......
package_task package lambda future thread

reversed 和 sorted 函数

a = 'abcxd' print(reversed(a)) # <reversed object at 0x000000000356F048> print(list(reversed(a))) # ['d', 'x', 'c', 'b', 'a'] print(sorted(a)) # ['a', ......
函数 reversed sorted

List 和 Map 区别;Arraylist 与 LinkedList 区别;ArrayList 与 Vector 区别;

一、概述 List是存储单列数据的集合,Map是存储键和值这样的双列数据的集合,List中存储的数据是有顺序,并且允许重复,值允许有多个null;Map中存储的数据是没有顺序的,键不能重复,值是可以有重复的,key最多有一个null。 二、明细 List 1)可以允许重复的对象。2)可以插入多个nu ......
LinkedList Arraylist ArrayList Vector List

Elasticsearch专题精讲—— REST APIs —— Document APIs —— Multi term vectors API

REST APIs —— Document APIs —— Multi term vectors API https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-multi-termvectors.html Retrieves ......
APIs Elasticsearch Document vectors 专题

Remove Duplicates from Sorted Array

**Example 1:** ``` Input: nums = [1,1,2] Output: 2, nums = [1,2,_] Explanation: Your function should return k = 2, with the first two elements of nums ......
Duplicates Remove Sorted Array from