政府网站改版建设/网络营销网络推广
文章目录
- 一、题目
- 二、题解
一、题目
1657. Determine if Two Strings Are Close
Two strings are considered close if you can attain one from the other using the following operations:
Operation 1: Swap any two existing characters.
For example, abcde -> aecdb
Operation 2: Transform every occurrence of one existing character into another existing character, and do the same with the other character.
For example, aacabb -> bbcbaa (all a’s turn into b’s, and all b’s turn into a’s)
You can use the operations on either string as many times as necessary.
Given two strings, word1 and word2, return true if word1 and word2 are close, and false otherwise.
Example 1:
Input: word1 = “abc”, word2 = “bca”
Output: true
Explanation: You can attain word2 from word1 in 2 operations.
Apply Operation 1: “abc” -> “acb”
Apply Operation 1: “acb” -> “bca”
Example 2:
Input: word1 = “a”, word2 = “aa”
Output: false
Explanation: It is impossible to attain word2 from word1, or vice versa, in any number of operations.
Example 3:
Input: word1 = “cabbba”, word2 = “abbccc”
Output: true
Explanation: You can attain word2 from word1 in 3 operations.
Apply Operation 1: “cabbba” -> “caabbb”
Apply Operation 2: “caabbb” -> “baaccc”
Apply Operation 2: “baaccc” -> “abbccc”
Constraints:
1 <= word1.length, word2.length <= 105
word1 and word2 contain only lowercase English letters.
题目来源: leetcode
二、题解
当两个字符串,所拥有的共同字符类型完全相同,且字母出现数目以及出现该数目的个数完全相同时,这两个字符串是close
的。
class Solution {
public:bool closeStrings(string word1, string word2) {int n1 = word1.length();int n2 = word2.length();vector<int> map1(26,0);vector<int> map2(26,0);vector<int> times(max(n1,n2) + 1,0);for(int i = 0;i < n1;i++) map1[word1[i] - 'a']++;for(int i = 0;i < n2;i++) map2[word2[i] - 'a']++;//如果有字母不在交集中for(int i = 0;i < 26;i++){if((map1[i] == 0 && map2[i] != 0) || (map1[i] != 0 && map2[i] == 0)) return false;}//统计出现次数的个数for(int i = 0;i < 26;i++){if(map1[i] != 0) {times[map1[i]]++; }}for(int i = 0;i < 26;i++){if(map2[i] != 0) times[map2[i]]--;if(times[map2[i]] < 0) return false;}return true;}
};
相关文章:

LeetCode75——Day22
文章目录 一、题目二、题解 一、题目 1657. Determine if Two Strings Are Close Two strings are considered close if you can attain one from the other using the following operations: Operation 1: Swap any two existing characters. For example, abcde -> aec…...

【SOC基础】单片机学习案例汇总 Part1:电机驱动、点亮LED
📢:如果你也对机器人、人工智能感兴趣,看来我们志同道合✨ 📢:不妨浏览一下我的博客主页【https://blog.csdn.net/weixin_51244852】 📢:文章若有幸对你有帮助,可点赞 👍…...

【HTML】HTML基础知识扫盲
1、什么是HTML? HTML是超文本标记语言(Hyper Text Markup Language)是用来描述网页的一种语言 注意: HTML不是编程语言,而是标记语言 HTML文件也可以直接称为网页,浏览器的作用就是读取HTML文件ÿ…...

【Mybatis-Plus】常见的@table类注解
目录 引入Mybatis-Plus依赖 TableName 当实体类的类名在转成小写后和数据库表名相同时 当实体类的类名在转成小写后和数据库表名不相同时 Tableld TableField 当数据库字段名与实体类成员不一致 成员变量名以is开头,且是布尔值 编辑 成员变量名与数据库关…...

Android WMS——操作View(七)
上一篇文章我们将 view 传递给 ViewRootImpl 进行操作,这里我们主要分析 ViewRootImpl 对 View 进行操作。在正式分析之前我们先来介绍以下 View。 一、View介绍 最开始学习 View 的时候最先分析的是它的布局(LinearLayout、FrameLayout、TableLayout、RelativeLayout、Abso…...

算法__数组排序_冒泡排序直接选择排序快速排序
文章目录 冒泡排序算法说明代码实现 直接选择排序算法说明代码实现 快速排序算法说明代码实现 本篇主要讲解数组排序相关的三种算法,冒泡排序,直接排序和快速排序。 冒泡排序 算法说明 在数组中依次比较相邻的两个元素,当满足左侧大于右侧时…...

ByteBuffer的原理和使用详解
ByteBuffer是字节缓冲区,主要用户读取和缓存字节数据,多用于网络编程,原生的类,存在不好用,Netty采用自己的ByteBuff,对其进行了改进 1.ByteBuffer的2种创建方式 1.ByteBuffer buf ByteBuffer.allocate(i…...

【MySql】10- 实践篇(八)
文章目录 1. 用动态的观点看加锁1.1 不等号条件里的等值查询1.2 等值查询的过程1.3 怎么看死锁?1.4 怎么看锁等待?1.5 update 的例子 2. 误删数据后怎么办?2.1 删除行2.2 误删库/表2.3 延迟复制备库2.4 预防误删库 / 表的方法2.4.1 账号分离2.4.2 制定操…...

【三方登录-Apple】iOS 苹果授权登录(sign in with Apple)之开发者配置一
记录一下sign in with Apple的开发者配置 前言 关于使用 Apple 登录 使用“通过 Apple 登录”可让用户设置帐户并使用其Apple ID登录您的应用程序和关联网站。首先使用“使用 Apple 登录”功能启用应用程序的App ID 。 如果您是首次启用应用程序 ID 或为新应用程序启用应用程序…...

可视化 | 数据可视化降维算法梳理
文章目录 📚数据描述🐇iris🐇MNIST 📚PCA🐇算法流程🐇图像描述 📚Kernel-PCA🐇算法流程🐇图像描述 📚MDS🐇算法流程🐇图像描述 &#…...

分布式:一文吃透分布式事务和seata事务
目录 一、事务基础概念二、分布式事务概念什么是分布式事务分布式事务场景CAP定理CAP理论理解CAPCAP的应用 BASE定理强一致性和最终一致性BASE理论 分布式事务分类刚性事务柔性事务 三、分布式事务解决方案方案汇总XA规范方案1:2PC第一阶段:准备阶段第二…...

Java架构师前沿技术
目录 1 导学2 信息物理系统2.1CPS的体系架构2.2 CPS的技术体系3 人工智能4 机器人5 边缘计算6 数字李生体7 云计算7.1 云计算的部署模式8 大数据想学习架构师构建流程请跳转:Java架构师系统架构设计 1 导学 2 信息物理系统 信息物理系统(CPS)是控制系统、嵌入式系统的扩展与…...

OpenCV ycrcb颜色空间
Opencv中有一个Ycrcb的选项,这个选项其实是Yuv444packet. 下面代码从文件中获取到一个yuv444planar的文件,通过手动转换,将其转为YcrCb,然后进行颜色空间csc. 所以可以确定这是一个packet的存储格式 def yuv444p_2_bgr8_opencv(…...

SPSS两独立样本t检验
前言: 本专栏参考教材为《SPSS22.0从入门到精通》,由于软件版本原因,部分内容有所改变,为适应软件版本的变化,特此创作此专栏便于大家学习。本专栏使用软件为:SPSS25.0 本专栏所有的数据文件请点击此链接下…...

视频格式高效转换:MP4视频批量转MKV格式的方法
随着数字媒体技术的不断发展,视频格式转换已经成为了我们日常工作中不可或缺的一部分。不同的视频格式适用于不同的场景和设备,因此将视频从一种格式转换为另一种格式往往是我们必须完成的任务。在本文中,我们将重点介绍如何运用云炫AI智剪高…...

0028Java程序设计-智能农场监控报警系统设计与实现
文章目录 摘要目 录系统设计开发环境 摘要 我国是一个以农业为主的国家,在当今社会信息化迅速发展的背景下,将信息技术与农业相融合是必然的趋势。现代信息技术在农业生产中的运用,主要体现在两个领域:一是传感器技术;…...

数据结构和算法——用C语言实现所有图状结构及相关算法
文章目录 前言图的基本概念图的存储方式邻接矩阵邻接表十字链表临界多重表 图的遍历最小生成树普里姆算法(Prim)克鲁斯卡尔算法(Kruskal) 最短路径BFS求最短路径迪杰斯特拉算法(Dijkstra)弗洛伊德算法&…...

JavaScript一些数据类型介绍
JavaScript一些数据类型介绍 1)数字类型(Number):可以表示整数和浮点数,例如:42、3.14159。 var x 42; // x 的类型是 Number var y 3.14159; // y 的类型是 Number2)字符串类型(…...

正向代理和反向代理与负载均衡
自存用 什么是反向代理,反向代理与正向代理的区别 一文帮你梳理清楚「正向代理和反向代理的区别与联系」 什么是反向代理服务器 正向代理为用户服务,给用户换个ip使其能访问其他网站 反向代理为服务器服务,使用户访问特定网站服务器。反向代…...

制造执行系统(MES)的核心功能是什么?
“一般来讲,制造执行系统(MES)的功能模块包括过程监控,质量管理,设备监控,计划执行等功能模块。” 为了深入探讨MES的核心功能,本文将从以下3个方面展开说明: 首先,从概…...

uniapp如何使用mumu模拟器
模拟器安装 下载地址:MuMu模拟器 模拟器相关设置 1.在设置-显示中选中手机版,设置手机分辨率 2.设置-关于手机-版本号快速点击,将其设置为开发者模式 3.选择多开器 4.打开hbuilderx,找到adb设置 5.配置adb路径及端口号&#x…...

【MATLAB源码-第64期】matlab基于DWA算法的机器人局部路径规划包含动态障碍物和静态障碍物。
操作环境: MATLAB 2022a 1、算法描述 动态窗口法(Dynamic Window Approach,DWA)是一种局部路径规划算法,常用于移动机器人的导航和避障。这种方法能够考虑机器人的动态约束,帮助机器人在复杂环境中安全、…...

阿里云国际版和国内版的区别是什么,为什么很多人喜欢选择国际版?
阿里云国际版和国内版区别如下: 谈到区别,我们不妨先来对比下相同点与不同点,才能清晰明确的知道二者区别 下面先介绍不同点: 面向市场更广泛 阿里云国际版主要是面向国际(全球)客户的,而国内…...

监听redis过期业务处理
配置类: package com.testimport org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.c…...

计算机网络与技术——数据链路层
😊计算机网络与技术——数据链路层 🚀前言☃️基本概念🥏封装成帧🥏透明传输🥏差错检测 ☃️点对点协议PPP🥏PPP协议的特点🥏PPP协议的帧格式🔍PPP异步传输时透明传输(字…...

UE5 Android下载zip文件并解压缩到指定位置
一、下载是使用市场的免费插件 二、解压缩是使用市场的免费插件 三、Android路径问题 windows平台下使用该插件没有问题,只是在Android平台下,只有使用绝对路径才能进行解压缩,所以如何获得Android下的绝对路径?增加C文件获得And…...

CSS3盒模型
CSS3盒模型规定了网页元素的显示方式,包括大小、边框、边界和补白等概念。2015年4月,W3C的CSS工作组发布了CSS3基本用户接口模块,该模块负责控制与用户接口界面相关效果的呈现方式。 1、盒模型基础 在网页设计中,经常会听到内容…...

VINS-Mono-VIO初始化 (五:视觉惯性对齐求解)
整体思想就是根据预积分的公式,把已知量和未知量各放到一边,因为前面的数据都是变换到 c 0 c_{0} c0下的,不是真正意义上和重力对齐的世界坐标,然后位移和速度的预积分中会用到加速度计获取的重力加速度g,但是这个重…...

详解Vue——的双向数据绑定是如何实现的?
引言 在现代的Web开发中,数据绑定是一个非常重要的概念。Vue.js是一种流行的JavaScript框架,它提供了一种简单而强大的方式来实现双向数据绑定。本文将介绍Vue的双向数据绑定原理,并提供相关代码示例。 什么是双向数据绑定? 双向…...

正则表达式引擎比较(翻译自:A comparison of regex engines)
原文: A comparison of regex engines – Rust Leipzig 引言 正则表达式(或简称regex)通常用于模式搜索算法。 有许多不同的正则表达式引擎提供不同的表达式支持、性能约束和语言绑定。 基于 John Maddock 之前的工作 (regex comparison)和…...