easy
-
1342. Number of Steps to Reduce a Number to Zero릿코드(LEETCODE) 2020. 2. 13. 11:29
https://leetcode.com/problems/number-of-steps-to-reduce-a-number-to-zero Source class Solution { public: int numberOfSteps (int num) { int sol = 1; while(num !=1){ int cand = num & 1; if(cand) { cand -= 1; sol++; } num /= 2; sol++; } return sol; } };
-
520. Detect Capital릿코드(LEETCODE) 2020. 2. 12. 11:07
https://leetcode.com/problems/detect-capital 문자열이 모두 대문자이거나 소문자 이거나 첫 문자가 대문자고 나머지가 소문자인 경우 true class Solution { public: bool detectCapitalUse(string word) { string str = word; std::transform(str.begin(), str.end(),str.begin(), ::toupper); bool isUpper = str == word; std::transform(str.begin(), str.end(),str.begin(), ::tolower); bool isLower = str == word; bool onlyOne = false; if(word[0] >= 'A..