第37天(中等题 数据结构)

news/2025/11/26 23:10:40/文章来源:https://www.cnblogs.com/wy0518/p/19274355

打卡第三十七天
2道中等题

image

题目:
image

思路:总数对-好数对=坏数对

代码:

class Solution {
public:long long countBadPairs(vector<int>& nums) {int n = nums.size();unordered_map<int,int> cnt;long long int ans = 1ll * n * (n - 1) / 2;for(int i =0;i < n;i++){ans -= cnt[nums[i] - i]; // 减去好数对cnt[nums[i] - i]++;// 更新计数}return ans;}
};

image

耗时≈一小时 明天继续

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/977750.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PostgreSQL权限管理实践

基于user模型 模式和用户同名 只有一个模式 # postgres用户连接 psql -U postgres -c "create user test password test;" psql -U postgres -c "create database testdb with owner=test;" psql…

预编译命令

本文介绍了C/C++中的预编译命令,重点讲解了`#include`、`#define`、`#if`和`#pragma`的使用方法与注意事项。`#include`用于文件包含,支持尖括号和双引号两种查找方式,并可嵌套包含;通过条件编译或`#pragma once`避…

2025 KEYDIY KD-MP: Add Keys for MLB MQB – Key Identification, Data, Calculation

The Key Replacement Challenge: Why Modern Vehicles Are a Headache For European and American automotive repair shops and car owners, replacing keys for MLB and MQB systems in Volkswagen Group vehicles (…

把 CLI 搬上 Web:在内网打造“可二开”的 AI IDE,为什么这条路更现实? - 指南

把 CLI 搬上 Web:在内网打造“可二开”的 AI IDE,为什么这条路更现实? - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-…

[LangChain] 23. 回调机制

invoke/stream() 方法,方法签名如下: invoke/stream(input: Input,options?: RunnableConfig ): AsyncGenerator<StreamEvent<Output>>1. 输入参数 (input) 类型:Input 与 invoke() 方法保持一致:如果…

本地环境自建的es重启,http和https访问es,nested数据类型及设置es别名

本地环境自建的es重启,http和https访问es,nested数据类型及设置es别名本地环境自建的es重启,http和https访问es,nested数据类型及设置es别名 link:https接口的支持判断,http升级到https需求https://www.cnblogs.com/…

一文入门 LangChain 开发

2024-05-22 [[Ollama]] [[N_LangChain]] [[N_LangGraph]] LangChain github langchain 项目页 github langgraph 项目页 官方文档 introduction 官方文档 0.2 introductio 0.2 langserve 官方文档 0.1 Components La…

freedom of speech

but N cannot be bad. I think its just the difference between cultures.

七、设备模型

一、概述kobject内核抽象出来的通用对象,对应/sys目录下的一个文件 kset是kobject的一个扩展,一个kset尅包含多个kobject,将多个kobject通过parent进行关联,实现了层次化的结构 sysfs虚拟文件系统,向用户空间提供…

Scrum冲刺阶段 Day Three

一、站立会议纪要 1. 已完成工作 后端开发:设计用户与文件表结构 实现注册登录接口 实现文件上传接口 实现全局异常处理 封装请求拦截器前端开发:搭建前端基础框架 开发注册登录页面2. 今日计划工作实现文件列表查询…

鼎鉴时代锋芒 智启品牌新章 ——2025品牌智鉴榜荣耀登临

当全球产业重构与消费升级浪潮澎湃交汇,品牌早已成为衡量时代实力的核心标尺,更是穿越周期、引领变革的核心力量。2024 品牌智鉴榜,以 “智识为基、专业为刃、价值为魂”,历经百日全域筛查、多维体系核验、业界权威…

深入解析:MTK5G旗舰系列——天玑9500/9400/9300/9200/9000在AI和处理器性能、DDR频率及UFS的深度对比分析

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

迈向人机共育的文明语法:AI元人文理论体系深度阐释——内观照叙事模型

迈向人机共育的文明语法:AI元人文理论体系深度阐释——内观照叙事模型 我们正站在一个文明史的奇点上。人工智能不再是遥远的科幻,而是深度介入社会运作、伦理决策与意义构建的“文明参与者”。传统的“价值对齐”范…

Day25综合案例一--CSS精灵--京东服务

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">…

Intellij扩展列表

开发idea插件,需要找到可用的扩展点,之前都是直接在网上搜索,最近详细看了下官方文档, 发现已经给我们列好了所有可用的扩展点 文档位置 https://plugins.jetbrains.com/docs/intellij/plugin-extensions.html#exp…

agentic terminal coding

opencode: https://github.com/sst/opencode The AI coding agent built for the terminalWhat is OpenCode? OpenCode is an open source agent that helps you write and run code directly from the terminal.[*] …

the badness of USA

it has no bad review. Maybe R/N/G can get the real worst some, but theres no even in the people they killed so much. so USA never changes. somehow.

Day3 Scrum冲刺博客

Day3 Scrum冲刺博客 1. 团队会议 todo补充会议照片 1)昨天已完成的工作前端实现个人设置弹窗以及问答模式静态页面,实现问答模式缓存 "关于我们"细节修正后端完成爬虫数据的数据清洗 增加爬虫程序适配的信…

完整教程:内核里常用宏BUG_ON/WARN_ON/WARN_ONCE

完整教程:内核里常用宏BUG_ON/WARN_ON/WARN_ONCE2025-11-26 22:27 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; displa…