Skip to content

Commit

Permalink
Create detect-capital.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Mar 19, 2017
1 parent b84c7c7 commit 5bf89ae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions C++/detect-capital.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Time: O(l)
// Space: O(1)

class Solution {
public:
bool detectCapitalUse(string word) {
int count = count_if(word.begin(), word.end(), [](char c){ return isupper(c); });
return count == word.length() || count == 0 || (count == 1 && isupper(word[0]));
}
};

0 comments on commit 5bf89ae

Please sign in to comment.