Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b779bf

Browse files
refactor 161
1 parenta9c5c8e commit1b779bf

File tree

1 file changed

+2
-29
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-29
lines changed

‎src/main/java/com/fishercoder/solutions/_161.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
packagecom.fishercoder.solutions;
22

3-
/**
4-
* 161. One Edit Distance
5-
*
6-
* Given two strings s and t, determine if they are both one edit distance apart.
7-
*
8-
* Note:
9-
* There are 3 possiblities to satisify one edit distance apart:
10-
* Insert a character into s to get t
11-
* Delete a character from s to get t
12-
* Replace a character of s to get t
13-
*
14-
* Example 1:
15-
* Input: s = "ab", t = "acb"
16-
* Output: true
17-
* Explanation: We can insert 'c' into s to get t.
18-
*
19-
* Example 2:
20-
* Input: s = "cab", t = "ad"
21-
* Output: false
22-
* Explanation: We cannot get t from s by only one step.
23-
*
24-
* Example 3:
25-
* Input: s = "1203", t = "1213"
26-
* Output: true
27-
* Explanation: We can replace '0' with '1' to get t.
28-
*/
293
publicclass_161 {
304
publicstaticclassSolution1 {
315
publicbooleanisOneEditDistance(Strings,Stringt) {
@@ -48,9 +22,8 @@ public boolean isOneEditDistance(String s, String t) {
4822
j++;
4923
}
5024
}
51-
returndiffCnt ==1
52-
||diffCnt
53-
==0;//it could be the last char of the longer is the different one, in that case, diffCnt remains to be zero
25+
returndiffCnt ==1 ||diffCnt ==0;
26+
//it could be the last char of the longer is the different one, in that case, diffCnt remains to be zero
5427
}elseif (s.length() ==t.length()) {
5528
intdiffCnt =0;
5629
for (inti =0;i <s.length();i++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp