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 bcbcdd9

Browse files
solves #2828: Check if a String Is an Acronym of Words in java
1 parent f54c9ca commit bcbcdd9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,4 @@
846846
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | |
847847
| 2815 | [Max Pair Sum in an Array](https://leetcode.com/problems/max-pair-sum-in-an-array) | [![Java](assets/java.png)](src/MaxPairSumInAnArray.java) | |
848848
| 2824 | [Count Pairs Whose Sum is Less than Target](https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target) | [![Java](assets/java.png)](src/CountPairsWhoseSumIsLessThanTarget.java) | |
849-
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/) | |
849+
| 2828 | [Check if a String Is an Acronym of Words](https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words) | [![Java](assets/java.png)](src/CheckIfAStringIsAnAcronymOfWords.java) | |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words
2+
// T: O(N)
3+
// S: O(1)
4+
5+
import java.util.List;
6+
7+
public class CheckIfAStringIsAnAcronymOfWords {
8+
public boolean isAcronym(List<String> words, String s) {
9+
if (words.size() != s.length()) {
10+
return false;
11+
}
12+
13+
for (int i = 0 ; i < words.size() ; i++) {
14+
if (words.get(i).charAt(0) != s.charAt(i)) {
15+
return false;
16+
}
17+
}
18+
19+
return true;
20+
}
21+
}

0 commit comments

Comments
(0)

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