본문 바로가기

분류 전체보기139

[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.
[C++ STL] unordered_map std::unordered_map This data structure is an associative container the contains key-value pairs with unique keys. Search, insertion, and removal of elements have average constane-time complexity Internally, the elements are not osorte in any particular order, but organized into buckets. Properties Associative container Unique keys Reference : https://en.cppreference.com/w/cpp/container/unordered.. 2023. 1. 16.
[C++ STL] map std::map Maps are associative containers that store elements formed by a combination of a key value and mapped value. The key values are generally used to sort and uniquely identify the elements The mapped values store the content associated to this key. The types of key and mapped value may differ. and both are grouped together by pair type typedef pair value_type; Internally, the elements in a.. 2023. 1. 16.
Dijkstras Algorithm (다익스트라 알고리즘) FunctionAlgorithm for finding the shortest paths between nodes in a graph It fixes a single node as the "source" node and finds shortest paths from the source to all other nodes in a graph It uses a data structure for storing and querying partial solutions sorted by distance from the "source" node (Queue, prioirty - Queue in C++) Time Complexityprioirty queue - $$ \Theta ((\left| V \right| + \le.. 2023. 1. 15.
[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.