분류 전체보기147 [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. 항은 2개의 인수를 받아들이는 함수로 계산되지 않습니다. [C/C++, visual studio] 문제 원인 함수와 변수가 구분되지 않는 경우 발생 대표적인 경우는 함수명과 동일한 변수가 존재하는 경우 예제 아래 코드에서는 maxRepeating과 이름이 동일한 변수가 함수의 출력 값을 저장하도록 선언됨 함수와 변수명이 같아 함수를 구분하지 못해 컴파일러가 에러를 발생시킴 #include int maxRepeating(char* sequence, char* word); int main() { char sequence[] = "aaabaaaabaaabaaaabaaaabaaaabaaaaba"; char word[] = "aaaba"; int maxRepeating = maxRepeating(sequence, word); return 0; } 2023. 1. 9. [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. [C++] Unordered Map (작성 중) 참조 자료 : https://en.cppreference.com/w/cpp/container/unordered_map std::unordered_map - cppreference.com (1) (since C++11) (2) (since C++17) Unordered map is an associative container that contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constant-time complexity. Internally, the elements are not sorted in any p en.cppreference.com 헤더파일 #include Uno.. 2023. 1. 8. [C++] vector container 주 언어가 C 다 보니, 코드 문제 풀이 사이트에서 자료구조가 필요할때 마다 직접 짜넣는게 매우 귀찮았다. C++이나 Python의 경우 기본적으로 자료구조가 구현되어 있다보니 부러운적이 많았다. (연산 시간 면에서는 C로 그냥 짜는게 훨 낫지만 말이다.) 본격 C++을 써야할 일이 생겨서, 공부하는 중에 Vector Container를 보고 무릎을 탁 쳤다. 진짜 편해서.. 오늘은 Vector Container에 대해 정리해보자. 1) vector Container 배열 + Stack 자료 구조가 합쳐진 역할을 수행한다. v.front(), v.back(), v.begin() 등 다양한 멤버함수가 존재한다. 2) vector 사용 헤더 파일을 추가해야 함 선언 방식 vector 변수 이름 ex) vec.. 2023. 1. 6. 이전 1 ··· 10 11 12 13 14 15 16 ··· 25 다음