Skip to content

Commit 0222bef

Browse files
committed
Add solution #520
1 parent 5da3422 commit 0222bef

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
476|[Number Complement](./0476-number-complement.js)|Easy|
132132
500|[Keyboard Row](./0500-keyboard-row.js)|Easy|
133133
506|[Relative Ranks](./0506-relative-ranks.js)|Easy|
134+
520|[Detect Capital](./0520-detect-capital.js)|Easy|
134135
541|[Reverse String II](./0541-reverse-string-ii.js)|Easy|
135136
542|[01 Matrix](./0542-01-matrix.js)|Medium|
136137
551|[Student Attendance Record I](./0551-student-attendance-record-i.js)|Easy|

solutions/0520-detect-capital.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 520. Detect Capital
3+
* https://leetcode.com/problems/detect-capital/
4+
* Difficulty: Easy
5+
*
6+
* We define the usage of capitals in a word to be right when one of the following
7+
* cases holds:
8+
* - All letters in this word are capitals, like "USA".
9+
* - All letters in this word are not capitals, like "leetcode".
10+
* - Only the first letter in this word is capital, like "Google".
11+
*
12+
* Given a string word, return true if the usage of capitals in it is right.
13+
*/
14+
15+
/**
16+
* @param {string} word
17+
* @return {boolean}
18+
*/
19+
var detectCapitalUse = function(word) {
20+
return /^[A-Z]?[a-z]+$|^[A-Z]+$/.test(word);
21+
};

0 commit comments

Comments
 (0)