{"id":28,"date":"2017-03-18T12:44:00","date_gmt":"2017-03-18T19:44:00","guid":{"rendered":"http:\/\/zxi.mytechroad.com\/blog\/?p=28"},"modified":"2018-04-19T08:45:20","modified_gmt":"2018-04-19T15:45:20","slug":"leetcode-520-detect-capital","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/leetcode\/leetcode-520-detect-capital\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 520. Detect Capital"},"content":{"rendered":"<p>Given a word, you need to judge whether the usage of capitals in it is right or not.<\/p>\n<p>We define the usage of capitals in a word to be right when one of the following cases holds:<\/p>\n<ol>\n<li>All letters in this word are capitals, like &#8220;USA&#8221;.<\/li>\n<li>All letters in this word are not capitals, like &#8220;leetcode&#8221;.<\/li>\n<li>Only the first letter in this word is capital if it has more than one letter, like &#8220;Google&#8221;.<\/li>\n<\/ol>\n<p>Otherwise, we define that this word doesn&#8217;t use capitals in a right way.<\/p>\n<p><b>Example 1:<\/b><\/p>\n<pre><b>Input:<\/b> \"USA\"\r\n<b>Output:<\/b> True\r\n<\/pre>\n<p><b>Example 2:<\/b><\/p>\n<pre><b>Input:<\/b> \"FlaG\"\r\n<b>Output:<\/b> False\r\n<\/pre>\n<p><b>Note:<\/b> The input will be a non-empty word consisting of uppercase and lowercase latin letters.<\/p>\n<pre class=\"tab-convert:true tab-size:2 lang:c++ decode:true \">class Solution {\r\npublic:\r\n    bool detectCapitalUse(string word) {\r\n        int n = std::count_if(word.begin(), word.end(), ::isupper);\r\n        return n == 0 || (n == 1 &amp;&amp; isupper(word[0])) || n == word.length();\r\n    }\r\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[22,4],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-leetcode","tag-case","tag-string","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":2739,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/2739"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}