博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - One Edit Distance
阅读量:7037 次
发布时间:2019-06-28

本文共 957 字,大约阅读时间需要 3 分钟。

Given two strings S and T, determine if they are both one edit distance apart.

1. 两个字符串的长度之差大于1,那么直接返回False

2. 两个字符串的长度之差等于1,那么长的那个字符串去掉一个字符,剩下的应该和短的字符串相同

3. 两个字符串的长度之差等于0,那么两个字符串对应位置的字符只能有一处不同。

public class Solution {        public static void main(String[] args){        String s = "test1";        String t = "test12";        System.out.println(isOneEditDistance(s,t));    }    public static boolean isOneEditDistance(String s, String t) {        int sl = s.length();        int tl = t.length();        if(Math.abs(sl - tl)>1){            return false;        }        if(sl - tl == 1){            return isDeleteOne(s, t);        }        if(tl - sl == 1){            return isDeleteOne(t,s);        }        if(tl == sl){            return isEditOne(s, t);        }        return false;       }        public static boolean isDeleteOne(String sLong, String sShort){        for(int i=0; i

  

转载于:https://www.cnblogs.com/incrediblechangshuo/p/9287751.html

你可能感兴趣的文章
编译安装与RPM安装的区别
查看>>
我的友情链接
查看>>
linux下ftp的安全巧用之pureftp!
查看>>
初始化AppWidget框架结构
查看>>
[PHP] 文件系统交互
查看>>
我的友情链接
查看>>
文本处理“三剑客”之SED"
查看>>
find应用示例
查看>>
Kmail身份验证组件
查看>>
拷贝构造函数为何传入引用?
查看>>
at命令及服务
查看>>
resin app server安装总结
查看>>
订单信息表和订单明细表
查看>>
背包九讲
查看>>
AS莫名报错 Error:Could not download junit.jar (junit:junit:4.12): No cached version available
查看>>
右侧客服 运动案例
查看>>
T4 Editor地址
查看>>
小程序文档
查看>>
QQ分享-定制分享卡片
查看>>
DataTable的用法
查看>>