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

Commitdcbae76

Browse files
committed
Modified 2 solutions
1 parentf0fa969 commitdcbae76

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
classSolution {
2-
publicintpeakIndexInMountainArray(int[]A) {
3-
returnpeakIndexInMountainArrayImpl(A,0,A.length-1);
2+
publicintpeakIndexInMountainArray(int[]A) {
3+
intlow =0;
4+
inthigh =A.length -1;
5+
while (low <high) {
6+
intmid =low + (high -low) /2;
7+
if (A[mid] <A[mid +1]) {
8+
low =mid +1;
9+
}
10+
else {
11+
high =mid;
12+
}
413
}
5-
6-
privateintpeakIndexInMountainArrayImpl(int[]arr,intstart,intend) {
7-
if (start >end)return -1;
8-
9-
intmid = (start +end)/2;
10-
11-
if (arr[mid] >arr[mid-1] &&arr[mid] >arr[mid+1]) {
12-
returnmid;
13-
}
14-
elseif (arr[mid] <arr[mid-1]) {
15-
returnpeakIndexInMountainArrayImpl(arr,start,mid-1);
16-
}
17-
else {
18-
returnpeakIndexInMountainArrayImpl(arr,mid+1,end);
19-
}
20-
}
14+
returnlow;
15+
}
2116
}

‎Easy/Unique Morse Code Words.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
classSolution {
2-
publicstaticintuniqueMorseRepresentations(String[]words) {
3-
String[]codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
4-
Set<String>set =newHashSet<>();
5-
6-
for (Stringword :words) {
7-
StringBuildersb =newStringBuilder();
8-
9-
for (charc :word.toCharArray()) {
10-
sb.append(codes[c-'a']);
11-
}
12-
13-
set.add(sb.toString());
14-
}
15-
16-
returnset.size();
2+
publicintuniqueMorseRepresentations(String[]words) {
3+
String[]morseCodes = {
4+
".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",
5+
".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."
6+
};
7+
Set<String>set =newHashSet<>();
8+
for (Stringword :words) {
9+
StringBuildersb =newStringBuilder();
10+
for (charc :word.toCharArray()) {
11+
sb.append(morseCodes[c -'a']);
12+
}
13+
set.add(sb.toString());
1714
}
15+
returnset.size();
16+
}
1817
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp