aboutsummaryrefslogtreecommitdiff
path: root/other/detect_capital.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/detect_capital.cpp')
-rw-r--r--other/detect_capital.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/other/detect_capital.cpp b/other/detect_capital.cpp
new file mode 100644
index 0000000..27aa46b
--- /dev/null
+++ b/other/detect_capital.cpp
@@ -0,0 +1,21 @@
+#include "leetcode.h"
+
+class Solution {
+public:
+ bool detectCapitalUse(string word) {
+ bool firstCaps = isupper(word[0]), allCaps = true, allLower = true;
+ for (int i = 1; i < word.size(); i++) {
+ if (isupper(word[i]))
+ allLower = false;
+ else
+ allCaps = false;
+ }
+ return (firstCaps && allCaps) || allLower;
+ }
+};
+
+int main() {
+ Solution obj;
+ testBool(obj.detectCapitalUse("USA")); // true
+ testBool(obj.detectCapitalUse("FlaG")); // false
+}