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 0ea62fc

Browse files
Create Generate Tag for Video Caption.java
1 parent c91e340 commit 0ea62fc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public String generateTag(String caption) {
3+
StringBuilder sb = new StringBuilder();
4+
sb.append('#');
5+
int idx = 0;
6+
int n = caption.length();
7+
while (idx < n && caption.charAt(idx) == ' ') {
8+
idx++;
9+
}
10+
boolean upperCase = false;
11+
while (idx < n) {
12+
if (Character.isLetter(caption.charAt(idx))) {
13+
if (upperCase) {
14+
sb.append(Character.toUpperCase(caption.charAt(idx)));
15+
upperCase = false;
16+
} else {
17+
sb.append(Character.toLowerCase(caption.charAt(idx)));
18+
}
19+
} else if (caption.charAt(idx) == ' ') {
20+
upperCase = true;
21+
}
22+
idx++;
23+
}
24+
return sb.toString().substring(0, Math.min(sb.length(), 100));
25+
}
26+
}

0 commit comments

Comments
(0)

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