File tree 5 files changed +60
-1
lines changed
5 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -31,4 +31,5 @@ All solutions will be accepted!
31
31
| 20| [ Valid Parentheses] ( https://leetcode-cn.com/problems/valid-parentheses/description/ ) | [ java/py/js] ( ./algorithms/ValidParentheses ) | Easy|
32
32
| 485| [ Max Consecutive Ones] ( https://leetcode-cn.com/problems/max-consecutive-ones/description/ ) | [ java/py/js] ( ./algorithms/MaxConsecutiveOnes ) | Easy|
33
33
| 191| [ Number Of 1 Bits] ( https://leetcode-cn.com/problems/number-of-1-bits/description/ ) | [ java/py/js] ( ./algorithms/NumberOf1Bits ) | Easy|
34
- | 258| [ Add Digits] ( https://leetcode-cn.com/problems/add-digits/description/ ) | [ java/py/js] ( ./algorithms/AddDigits ) | Easy|
34
+ | 258| [ Add Digits] ( https://leetcode-cn.com/problems/add-digits/description/ ) | [ java/py/js] ( ./algorithms/AddDigits ) | Easy|
35
+ | 520| [ Detect Capital] ( https://leetcode-cn.com/problems/detect-capital/description/ ) | [ java/py/js] ( ./algorithms/DetectCaptial ) | Easy|
Original file line number Diff line number Diff line change
1
+ # Detect Capital
2
+ This problem is easy to solve
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean detectCapitalUse (String word ) {
3
+ int upperCount = 0 ,
4
+ lowerCount = 0 ;
5
+ for (char c : word .toCharArray ()) {
6
+ int v = (int ) c ;
7
+ if (65 <= v && v <= 90 ) {
8
+ if (lowerCount > 0 ) return false ;
9
+ upperCount += 1 ;
10
+ } else {
11
+ if (upperCount > 1 ) return false ;
12
+ lowerCount += 1 ;
13
+ }
14
+ }
15
+ return true ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } word
3
+ * @return {boolean }
4
+ */
5
+ var detectCapitalUse = function ( word ) {
6
+ let upperCount = 0 ,
7
+ lowerCount = 0 ,
8
+ list = word . split ( '' )
9
+
10
+ for ( let i = 0 ; i < list . length ; i ++ ) {
11
+ if ( 65 <= list [ i ] . charCodeAt ( 0 ) && list [ i ] . charCodeAt ( 0 ) <= 90 ) {
12
+ if ( lowerCount > 0 ) return false
13
+ upperCount += 1
14
+ } else {
15
+ if ( upperCount > 1 ) return false
16
+ lowerCount += 1
17
+ }
18
+ }
19
+
20
+ return true
21
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def detectCapitalUse (self , word ):
3
+ """
4
+ :type word: str
5
+ :rtype: bool
6
+ """
7
+ upper_count = 0
8
+ lower_count = 0
9
+ for c in word :
10
+ if 65 <= ord (c ) <= 90 :
11
+ if lower_count > 0 :
12
+ return False
13
+ upper_count += 1
14
+ else :
15
+ if upper_count > 1 :
16
+ return False
17
+ lower_count += 1
18
+ return True
You can’t perform that action at this time.
0 commit comments