当前位置:网站首页>Leetcode 161 Editing distance of 1 (2022.06.10)
Leetcode 161 Editing distance of 1 (2022.06.10)
2022-06-11 04:58:00 【ChaoYue_ miku】
Given two strings s and t , If their edit distance is 1 , Then return to true , Otherwise return to false .
character string s And string t The editing distance between them is equal to 1 There are three possible situations :
Go to s Insert Just one Character get t
from s Delete in Just one Character get t
stay s of use A different character Replace Just one Character get t
Example 1:
Input : s = “ab”, t = “acb”
Output : true
explain : Can be ‘c’ Insert string s To get t.
Example 2:
Input : s = “cab”, t = “ad”
Output : false
explain : Unable to get 1 Step operation s Turn into t.
Tips :
0 <= s.length, t.length <= 104
s and t It's made up of lowercase letters , Capital letters and numbers
source : Power button (LeetCode)
link :https://leetcode.cn/problems/one-edit-distance
Method 1 : Double pointer
Python3 Submission :
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
边栏推荐
- [markdown syntax advanced] make your blog more exciting (III: common icon templates)
- Parametric contractual learning: comparative learning in long tail problems
- 华为设备配置BGP/MPLS IP 虚拟专用网命令
- Yolov5 training personal data set summary
- Analysis of 17 questions in Volume 1 of the new college entrance examination in 2022
- C language test question 3 (grammar multiple choice question - including detailed explanation of knowledge points)
- DL deep learning experiment management script
- Batch naming picture names
- Legend has it that setting shader attributes with shader ID can improve efficiency:)
- The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation
猜你喜欢

Decision tree (hunt, ID3, C4.5, cart)

IOU series (IOU, giou, Diou, CIO)

华为设备配置跨域虚拟专用网

Analysis of 17 questions in Volume 1 of the new college entrance examination in 2022

codesys 获取系统时间

Reverse thinking: making cartoon photos real

What are the similarities and differences between the data center and the data warehouse?

Huawei equipment configuration MCE

Paper reproduction: expressive body capture
![[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection](/img/97/a3e91e703b01aaceeb0d61545f9609.jpg)
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
随机推荐
CoDeSys get system time
Redis master-slave replication, sentinel, cluster cluster principle + experiment (wait, it will be later, but it will be better)
Codesys get System Time
Free data | new library online | cnopendata data data of national heritage stores and auction enterprises
Paper reproduction: expressive body capture
Cartographer learning record: cartographer Map 3D visualization configuration (self recording dataset version)
Tips and websites for selecting papers
Go unit test example; Document reading and writing; serialize
课程设计总结
Cross modal retrieval | visual representation learning
C language test question 3 (grammar multiple choice question - including detailed explanation of knowledge points)
Lr-link Lianrui fully understands the server network card
【Markdown语法高级】 让你的博客更精彩(三:常用图标模板)
Detailed explanation of network security bypass network card
Lianrui electronics made an appointment with you with SIFA to see two network cards in the industry's leading industrial automation field first
华为设备配置本地虚拟专用网互访
Powerful new UI installation force artifact wechat applet source code + multiple templates support multiple traffic main modes
董明珠称“格力手机做得不比苹果差”哪里来的底气?
免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据
MySQL regularly deletes expired data.