当前位置:网站首页>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
边栏推荐
- Use of mmdetection
- How to calculate the handling charge of international futures gold?
- 一大厂95后程序员对部门领导不满,删库跑路被判刑
- Lianrui electronics made an appointment with you with SIFA to see two network cards in the industry's leading industrial automation field first
- Cross modal retrieval | visual representation learning
- Go unit test example; Document reading and writing; serialize
- Leetcode question brushing series - mode 2 (datastructure linked list) - 725 (m): split linked list in parts
- Best practices and principles of lean product development system
- Writing a good research title: Tips & Things to avoid
- Google drive download failed, network error
猜你喜欢

Support vector machine -svm+ source code

Thesis 𞓜 jointly pre training transformers on unpaired images and text

Carbon path first, Huawei digital energy injects new momentum into the green development of Guangxi

PostgreSQL database replication - background first-class citizen process walreceiver receiving and sending logic

博途仿真时出现“没有针对此地址组态任何硬件,无法进行修改”解决办法

四大MQ的区别

Using keras to build the basic model yingtailing flower

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

oh my zsh正确安装姿势
![[Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer](/img/33/32796e4f807db99898d471ac5dfe2c.jpg)
[Transformer]AutoFormerV2:Searching the Search Space of Vision Transformer
随机推荐
Meedu knowledge payment solution v4.5.4 source code
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
Codesys get System Time
Technical dry goods: how to select the most suitable RDMA network card
Differences between the four MQ
go MPG
C language test question 3 (advanced program multiple choice questions _ including detailed explanation of knowledge points)
2020-12-24
How can smart construction sites achieve digital transformation?
RGB image histogram equalization and visualization matlab code
CoDeSys get system time
go MPG
The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation
Leetcode question brushing series - mode 2 (datastructure linked list) - 21:merge two sorted lists merge two ordered linked lists
华为设备配置MCE
[Transformer]CoAtNet:Marrying Convolution and Attention for All Data Sizes
Huawei equipment is configured with bgp/mpls IP virtual private network address space overlap
免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据
博途仿真时出现“没有针对此地址组态任何硬件,无法进行修改”解决办法
Google drive download failed, network error