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

Commit c27b2cc

Browse files
nextcommit
1 parent bd6a3b6 commit c27b2cc

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

‎src/revision/EditDistance.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package revision;
2+
3+
public class EditDistance {
4+
5+
6+
public static int edit(String s1, String s2) {
7+
8+
9+
if (s1.length() == 0) {
10+
return s2.length();
11+
}
12+
if (s2.length() == 0) {
13+
return s1.length();
14+
}
15+
16+
17+
if (s1.charAt(0) == s2.charAt(0)) {
18+
return edit(s1.substring(1), s2.substring(1));
19+
}
20+
21+
else {
22+
23+
// insert
24+
int x = edit(s1.substring(1), s2) + 1;
25+
26+
27+
// delete
28+
int y = edit(s1, s2.substring(1)) + 1;
29+
30+
// replace
31+
int z = edit(s1.substring(1), s2.substring(1)) + 1;
32+
33+
return Math.min(x, Math.min(y, z));
34+
35+
}
36+
37+
38+
39+
}
40+
41+
42+
43+
public static void main(String[] args) {
44+
45+
System.out.println(edit("geek", "geeks"));
46+
47+
}
48+
49+
50+
}

‎src/revision/InternetAddress.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package revision;
2+
3+
public class InternetAddress {
4+
5+
public static void solution(String str) {
6+
7+
String res = "";
8+
int index = 0;
9+
if (str.charAt(0) == 'h') {
10+
11+
res += "http://";
12+
index = 4;
13+
14+
} else {
15+
res += "ftp://";
16+
index = 3;
17+
}
18+
19+
int pos = -1;
20+
for (int i = str.length() - 2; i >= index; i--) {
21+
22+
if (str.charAt(i) == 'r' && str.charAt(i + 1) == 'u') {
23+
pos = i;
24+
25+
}
26+
}
27+
if (pos >= 0 && pos < str.length()) {
28+
res += str.substring(index, pos);
29+
30+
if (pos == str.length() - 2) {
31+
res += ".ru/";
32+
} else {
33+
res += ".ru/";
34+
res += str.substring(pos + 2);
35+
}
36+
37+
38+
}
39+
40+
System.out.println(res);
41+
42+
43+
}
44+
45+
public static void main(String[] args) {
46+
47+
solution("httpsunrux");
48+
}
49+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /