Skip to content

Commit 0ea62fc

Browse files
authored
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)