Problem Solving/리트코드(leetcode) (29) 썸네일형 리스트형 Determine if String Halves Are Alike class Solution { public: bool halvesAreAlike(string s) { string a = s.substr(0, s.length()/2); string b = s.substr(s.length()/2, s.length()); int acnt = 0, bcnt = 0; for(int i = 0; i Valid Perfect Square class Solution { public: bool isPerfectSquare(int num) { return ceil(sqrt(num)) == floor(sqrt(num)) ? true : false; } }; Sqrt(x) class Solution { public: int mySqrt(int x) { return floor(sqrt(x)); } }; Self Dividing Numbers class Solution { public: vector selfDividingNumbers(int left, int right) { vector answer; int temp = 0, div = 0; for(int i = left; i Power of Four class Solution { public: bool isPowerOfFour(int n) { if(n == 0) return false; if(ceil(log(n) / log(4)) == floor(log(n) / log(4))) return true; else return false; } }; Lemonade Change class Solution { public: bool lemonadeChange(vector& bills) { int bills5 = 0; int bills10 = 0; int bills20 = 0; for(int i = 0; i 0) { bills10--; bills5--; } else { bills5 -= 3; bills20++; } } if(bills5 Add Digits class Solution { public: int addDigits(int num) { return num != 0 && num % 9 == 0 ? 9 : num % 9; } }; Summary Ranges class Solution { public: vector summaryRanges(vector& nums) { vector vec; for (int i = 0, n = nums.size(); i 이전 1 2 3 4 다음