当前位置:网站首页>力扣(LeetCode)161. 相隔为 1 的编辑距离(2022.06.10)
力扣(LeetCode)161. 相隔为 1 的编辑距离(2022.06.10)
2022-06-11 04:46:00 【ChaoYue_miku】
给定两个字符串 s 和 t ,如果它们的编辑距离为 1 ,则返回 true ,否则返回 false 。
字符串 s 和字符串 t 之间满足编辑距离等于 1 有三种可能的情形:
往 s 中插入 恰好一个 字符得到 t
从 s 中删除 恰好一个 字符得到 t
在 s 中用 一个不同的字符 替换 恰好一个 字符得到 t
示例 1:
输入: s = “ab”, t = “acb”
输出: true
解释: 可以将 ‘c’ 插入字符串 s 来得到 t。
示例 2:
输入: s = “cab”, t = “ad”
输出: false
解释: 无法通过 1 步操作使 s 变为 t。
提示:
0 <= s.length, t.length <= 104
s 和 t 由小写字母,大写字母和数字组成
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/one-edit-distance
方法一:双指针
Python3提交内容:
class Solution:
def isOneEditDistance(self, s: str, t: str) -> bool:
i = j = 0
while(i < len(s) and j < len(t)):
if s[i] == t[j]:
i += 1
j += 1
else:
return (s[i+1:] == t[j:]) or (s[i:] == t[j+1:]) or (s[i+1:] == t[j+1:])
return abs(len(s) - len(t)) == 1
边栏推荐
- Writing a good research title: Tips & Things to avoid
- How to quickly find the official routine of STM32 Series MCU
- New product release: Lianrui launched a dual port 10 Gigabit bypass network card
- Leetcode question brushing series - mode 2 (datastructure linked list) - 19:remove nth node from end of list (medium) delete the penultimate node in the linked list
- [Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer
- Crmeb/v4.4 Standard Version open version mall source code applet official account h5+app mall source code
- Cartographer learning record: cartographer Map 3D visualization configuration (self recording dataset version)
- Comparison of gigabit network card chips: who is better, a rising star or a Jianghu elder?
- Holiday Homework
- What is a smart network card? What is the function of the smart network card?
猜你喜欢

New library goes online | cnopendata immovable cultural relic data

PCB ground wire design_ Single point grounding_ Bobbin line bold
![[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection](/img/97/a3e91e703b01aaceeb0d61545f9609.jpg)
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection

Google Code Coverage best practices

免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据

Check the digital tube with a multimeter

PHP phone charge recharge channel website complete operation source code / full decryption without authorization / docking with the contract free payment interface

Cartographer learning record: cartographer Map 3D visualization configuration (self recording dataset version)

New product pre-sale: 25g optical network card based on Intel 800 series is coming

USB to 232 to TTL overview
随机推荐
Google drive download failed, network error
The 4th small class discussion class on fundamentals of information and communication
MySQL regularly deletes expired data.
关于串口波特率的的记录
Network security construction in 5g Era
Yolact paper reading and analysis
Network adapter purchase guide
RGB image histogram equalization and visualization matlab code
Differences between the four MQ
C language test question 3 (advanced program multiple choice questions _ including detailed explanation of knowledge points)
exness:流动性系列-订单块、不平衡(二)
C语言试题三(语法选择题——含知识点详解)
华为设备配置通过GRE接入虚拟专用网
New library goes online | cnopendata immovable cultural relic data
Decision tree (hunt, ID3, C4.5, cart)
The data center is evolving towards the "four high" trend, and the OCP network card and the whole cabinet will be delivered into the mainstream of the future data center
lower_bound,upper_bound,二分
PostgreSQL数据库复制——后台一等公民进程WalReceiver 收发逻辑
The first master account of Chia Tai International till autumn
DL deep learning experiment management script