Skip to content

Commit 704da9f

Browse files
committed
feat(leetcode): add No.2833
1 parent 899283f commit 704da9f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/description/
2+
// algorithms
3+
// Easy (63.24%)
4+
// Total Accepted: 38.7K
5+
// Total Submissions: 61.2K
6+
7+
class Solution {
8+
9+
private static final char L = 'L';
10+
private static final char R = 'R';
11+
private static final char ANY = '_';
12+
13+
public int furthestDistanceFromOrigin(String moves) {
14+
int lNum = 0;
15+
int rNum = 0;
16+
int anyNum = 0;
17+
18+
for (char ch : moves.toCharArray()) {
19+
if (L == ch) {
20+
lNum++;
21+
} else if (R == ch) {
22+
rNum++;
23+
} else if (ANY == ch) {
24+
anyNum++;
25+
}
26+
}
27+
28+
return Math.abs(lNum - rNum) + anyNum;
29+
}
30+
31+
}

0 commit comments

Comments
 (0)