CPP3 [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. qsort This contents is referenced from here : (https://en.cppreference.com/w/c/algorithm/qsort) There is default qsort() function in c and cpp basic library. If you don't have good function for sorting, qsort is great alternatives. qsort - Sorts elements of given array point in ascending order void qsort(void *ptr, size_t count, size_t size, int (*comp)(const void *, const void *) ); parameters ptr - .. 2023. 1. 2. 이전 1 다음