Leetcode18 [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] 1. Two Sum Solution Brute Force Time Complexity : O(N^2) Space Omplexity : O(1) class Solution { public: vector twoSum(vector& nums, int target) { vector RetVal; for (int i = 0; i != nums.size(); ++i) { for (int j = i + 1; j != nums.size(); ++j) { if ((nums[i] + nums[j]) == target) { RetVal.push_back(i); RetVal.push_back(j); return RetVal; } } } RetVal.push_back(-1); RetVal.push_back(-1); return RetVal; } }; 2023. 1. 9. [LeetCode] 1030. Matrix Cells in Distance Order, C++ Solution Use Queue First time to use C++ STL, it is very useful than coding data structure one by one in C #include #include // BFS Solution // Use Queue // Use STL -> Easy typedef struct myStruct { int RowIdx; int ColumnIdx; int depth; }myStruct; using namespace std; void BFS(int row, int column, queue* pmy_queue, vector* pmyvector); int gArr[100][100] = { 0 }; int main() { queue my_queue; vect.. 2023. 1. 9. [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. 이전 1 2 3 다음