-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDetect Capital.cpp
39 lines (23 loc) · 943 Bytes
/
Detect Capital.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Solution by Rahul Surana
***********************************************************
We define the usage of capitals in a word to be right when one of the following cases holds:
All letters in this word are capitals, like "USA".
All letters in this word are not capitals, like "leetcode".
Only the first letter in this word is capital, like "Google".
Given a string word, return true if the usage of capitals in it is right.
***********************************************************
*/
#include<bits/stdc++.h>
class Solution {
public:
bool detectCapitalUse(string word) {
int c = 0;
for(int i= 0 ;i < word.length(); i++){
if(word[i] >= 'A' && word[i] <='Z') c++;
}
if(c == word.length() || c == 0) return true;
if(c == 1 && word[0] >='A' && word[0] <='Z') return true;
return false;
}
};