코딩 문제31 [Leet Code] 231. Power of Two, C++ Solution - Use Bitwise operator class Solution { public: bool isPowerOfTwo(int n) { if (n < 0) { return false; } else { return n && !(n & n - 1); } } }; 2023. 1. 17. [LeetCode] 2331. Evaluate Boolean Binary Tree, cpp Solution use recursive structure Tag Full binary tree class Solution { public: bool evaluateTree(TreeNode* root) { bool retval = true; if (root->left != nullptr && root->left != nullptr) // full binary tree { if (root->val == 2) // OR { retval = evaluateTree(root->left) || evaluateTree(root->right);; } else // operta = 3, AND { retval = evaluateTree(root->left) && evaluateTree(root->right);; } }.. 2023. 1. 10. [LeetCode] 1880. Check if Word Equals Summation of Two Words, C Solution Use ASCII transformation lower case english letter to integer #include int GetNumericValue(char* ArrWord); bool isSumEqual(char* firstWord, char* secondWord, char* targetWord) { bool RetVal = true; int fisrtWordNumericValue = GetNumericValue(firstWord); int secondWordNumericValue = GetNumericValue(secondWord); int targetWordNumericValue = GetNumericValue(targetWord); if (targetWordNumer.. 2023. 1. 5. [LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C Solution - Use qsort(2D array, 2 column) & Greedy Algorithms - Time Limit Exceed int minGroups(int** intervals, int intervalsSize, int* intervalsColsize) { int i = 0; int** RefArr; int RefArrSize = intervalsSize; int** TmpArr; int TmpArrSize = intervalsSize; int NumOfGroup = 0; int StartIndex = 0; int EndIndex = 0; // Sort qsort(intervals, intervalsSize, sizeof(intervals[0]), compare2Darray2Colu.. 2023. 1. 2. [LeetCode] 1614. Maximum Nesting Depth of the Parenthesesm, C Solution - Simple Count of Max Depth Time Complexity O(n) Space Complexity O(n) int maxDpeth(char* s); int main() { char string[] = "(1)+((2))+(((3)))"; int RetVal; RetVal = maxDpeth(string); return 0; } int maxDpeth(char* s) { int Depth = 0; int MaxDepth = 0; int NumOfChar = 0; while (s[NumOfChar] != '\0') { if (s[NumOfChar] == '(') { ++Depth; } else if (s[NumOfChar] == ')') { --Depth; } else {.. 2023. 1. 1. [LeetCode] 2283. Check if Number Has Equal Digit Count and Digit Value, C Solution - Use Hash Table Time Complexity O(n) Space Complexity O(n) #include bool digitCount(char* pnum); int main() { char string[] = "030"; bool RetVal; RetVal = digitCount(string); return 0; } bool digitCount(char* pnum) { bool bRetVal = true; const int ASCIINumberInit = 48; int i = 0; int NumOfChar = 0; int arrHashTable[10] = { 0 }; while (pnum[NumOfChar] != '\0') { arrHashTable[pnum[NumOfC.. 2023. 1. 1. 이전 1 2 3 4 5 6 다음