Google面试题:M-One Edit Distance
来源:互联网 发布:天谕男玉虚捏脸数据 编辑:程序博客网 时间:2024/05/29 10:40
http://www.jiuzhang.com/article/Google2016Experience%20%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B%E5%B8%88onsite/
http://www.lintcode.com/zh-cn/problem/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) { if(s==null || t==null) return false; int n1 = s.length(); int n2 = t.length(); if(Math.abs(n1-n2)>1) return false; for(int i=0; i<Math.min(n1,n2); i++){ if(s.charAt(i)!=t.charAt(i)){ if(n1>n2) return s.substring(i+1,s.length()).equals(t.substring(i,t.length())); else if(n1<n2) return s.substring(i,s.length()).equals(t.substring(i+1,t.length())); else return s.substring(i+1,s.length()).equals(t.substring(i+1,t.length())); } } return Math.abs(n1-n2)==1; }}
阅读全文
0 0
- Google面试题:M-One Edit Distance
- Geeks面试题: Edit Distance
- One Edit Distance
- One Edit Distance
- Leetcode One Edit Distance
- One Edit Distance
- one edit distance python
- LeetCode - One Edit Distance
- One Edit Distance
- leetcode - One Edit Distance
- #leetcode#One Edit Distance
- [LeetCode]One Edit Distance
- [LeetCode161] One Edit Distance
- 161. One Edit Distance
- One Edit Distance
- One Edit Distance
- One Edit Distance
- One Edit Distance
- MySQL存储引擎 / MySQL字符集 / MySQL分片 / mysql 存储量
- 直白解读linux下pthread的简单操作
- ssh框架整合开发
- MyBatis实现Mysql数据库分库分表操作和总结
- ccf 201604-4游戏
- Google面试题:M-One Edit Distance
- 汇编--条件跳转指令
- Java String Split()用法小结
- MongoDB 备份与恢复
- 配置文件log4j详解
- shell中$(( )) 与 $( ) 还有${ }的区别
- 自动化基础普及之selenium是啥?
- 多线程(互斥锁、读写锁、条件变量、信号量、自旋锁)相关
- LED配置移植说明