Edit Distance II
Given two strings S and T, determine if they are both one edit distance apart.
Given s = "aDb", t = "adb"
return true
public class Solution {
/**
* @param s a string
* @param t a string
* @return true if they are both one edit distance apart or false
*/
public boolean isOneEditDistance(String s, String t) {
// Write your code here
if(s==null||t==null) return true;
if(s!=null&&t==null||s==null&&t!=null) return false;
int sLen = s.length();
int tLen = t.length();
if(Math.abs(sLen-tLen)>=2) return false;
for(int i=0; i<Math.min(sLen, tLen);i++){
if(s.charAt(i) != t.charAt(i)){
if(sLen==tLen ){
return s.substring(i+1, sLen).equals(t.substring(i+1, tLen));
} else if (sLen< tLen ){
return s.substring(i, sLen).equals(t.substring(i+1, tLen));
} else if (sLen> tLen ){
return s.substring(i+1, sLen).equals(t.substring(i, tLen));
}
}
}
if(sLen==tLen){
return false;
}else{
return true;
}
}
}
Edit Distance II的更多相关文章
- 动态规划小结 - 二维动态规划 - 时间复杂度 O(n*n)的棋盘型,题 [LeetCode] Minimum Path Sum,Unique Paths II,Edit Distance
引言 二维动态规划中最常见的是棋盘型二维动态规划. 即 func(i, j) 往往只和 func(i-1, j-1), func(i-1, j) 以及 func(i, j-1) 有关 这种情况下,时间 ...
- stanford NLP学习笔记3:最小编辑距离(Minimum Edit Distance)
I. 最小编辑距离的定义 最小编辑距离旨在定义两个字符串之间的相似度(word similarity).定义相似度可以用于拼写纠错,计算生物学上的序列比对,机器翻译,信息提取,语音识别等. 编辑距离就 ...
- [LeetCode] 72. Edit Distance(最短编辑距离)
传送门 Description Given two words word1 and word2, find the minimum number of steps required to conver ...
- [LeetCode] One Edit Distance 一个编辑距离
Given two strings S and T, determine if they are both one edit distance apart. 这道题是之前那道Edit Distance ...
- [LeetCode] Edit Distance 编辑距离
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...
- Edit Distance
Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert ...
- 编辑距离——Edit Distance
编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...
- LintCode Edit Distance
LintCode Edit Distance Given two words word1 and word2, find the minimum number of steps required to ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
随机推荐
- keil MDK注意事项
1.MDK中的char类型的取值范围是? 在MDK中,默认情况下,char 类型的数据项是无符号的,所以它的取值范围是0-255.它们可以显式地声明为signed char 或 unsigned.因此 ...
- WPF——UI布局
1.规划整体布局(规划界面结构)——>这样就可以划分出若干区域(区域的控件通常是一些容器控件) 2.针对 上面的 “若干区域” ,制作每个区域的一级用户控件(然后,将该用户控件放入对应的区域中) ...
- 使用Vuex来处理Authentication token
https://www.cnblogs.com/chentianwei/p/10156459.html 之前博客:建立了一个app.使用loacal storage 来管理tokens(通过clien ...
- 智能合约语言 Solidity 教程系列10 - 完全理解函数修改器
这是Solidity教程系列文章第10篇,带大家完全理解Solidity的函数修改器. Solidity系列完整的文章列表请查看分类-Solidity. 写在前面 Solidity 是以太坊智能合约编 ...
- Linux系统中文件定位与查找
Linux系统中文件查找 关键词 文件查找 | find | locate 本文主要介绍有关文件查找的两个命令——find和locate,以及压缩打包的命令——compress, gzip,bzip2 ...
- Pudding Monsters CodeForces - 526F (分治, 双指针)
大意: n*n棋盘, n个点有怪兽, 求有多少边长为k的正方形内恰好有k只怪兽, 输出k=1,...,n时的答案和. 等价于给定n排列, 对于任意一个长为$k$的区间, 若最大值最小值的差恰好为k, ...
- 如何查找php-fpm监听的端口
1. 找到php的安装位置.如: /usr/local/php-7.3.3 2. 进入安装目录下的etc/php-fpm.d目录,然后你会看到: 3. 打开www.conf,搜索listen关键字,你 ...
- DVWA-CSRF
Low等级 image 抓包 image 正常跳转 image image 在这里我们把密码改为qwer image image image image image ...
- 整体二分求动态区间第k大
比树状数组套主席树不知道高到哪里去了,solve(l,r,L,R)就是对于L,R的操作区间的答案都在l,r区间里,然后递归下去 复杂度O(nlognlogn),每个操作会执行logn次就是o(nlog ...
- Leetcode 145
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...