Algorithm (68) 썸네일형 리스트형 [SAP/C++] BST from postorder 난이도 : 중 후순위 운행으로 이진탐색 트리 만들기 BST : Binary Search Tree (이진 탐색 트리) 이진 탐색 트리 : 탐색하고자 하는 key값을 배열의 중앙값과 비교하여, 크면 오른쪽 list에 존재하고, 작으면 왼쪽 list에 존재한다. PostOrder : 후순위 운행 L->R->V 순으로 탐색을 진행 후순위 운행으로 주어진 그래프를 탐색하여, 이를 BST로 만들기 이때 그래프는 배열로 주어져있음 // postorder : 후순위 운행 L-R-V Node* BST(Node* root,int key) { if(root==NULL) root=new Node(key); else if(root->data > key) root->left=BST(root->left,key); //root->l.. [SAP/C++] Mirror Tree 중 Mirror Tree 문제내용은 말 그대로 입력받은 트리를 반전시키는 것 생각) 일단 트리를 맨 아래까지 탐색해서 NULL이 나오면 리턴 해준 후 오른쪽과 왼쪽을 바꿔주면 될 것 같다 근데, 맨 아래까지 탐색하는 것을 DFS에 너무 생각이 한정되어 있다보니 어떻게 해야할지 여러가지 시도를 해봤는데.. 생각해보니 재귀로 하면 엄청 간단하게 가능하다 ㅠㅠ 연습이 많이 부족한걸 느낌... /* A binary tree node has data, pointer to left child and a pointer to right child / struct Node { int data; struct Node* left; struct Node* right; Node(int x){ data = x; left = ri.. [SAP/C++] reversed Linked List 난이도 중 역순 연결리스트 만들기 practice.geeksforgeeks.org/problems/reverse-a-linked-list/1/?company[]=SAP%20Labs&company[]=SAP%20Labs&page=1&query=company[]SAP%20Labspage1company[]SAP%20Labs Reverse a linked list | Practice | GeeksforGeeks practice.geeksforgeeks.org 코드 /* Linked List Node structure: struct Node { int data; struct Node *next; } */ class Solution { public: //Function to reverse a linked list... [SAP/C++]Check Circular Linked List 난이도 : 중하 문제) linked list의 head pointer를 input으로 받아 해당 리스트가 circular linked list인지, 아닌지를 반환한다(bool) 연결리스트를 한번 복습해봤다 다음에서 보면, 2번이 바로 circular linked list인데 마지막 node의 next가 처음 node를 가리키고있으며, 처음 node는 항상 head포인터에 의해 가리켜지고있다. 즉, 처음 node에서 시작하여 계속해서 next -> next로 탐색하다가, head포인터가 가리키는 노드와 같아지는 때가 오면, circular linked list일 것이고. 1번 그림과 같이 탐색중에 NULL을 만나면, circular linked list가 아닐 것! /* Link list Node stru.. [SAP/C++] Remove Space 난이도 하 스페이스 제거문제 k개의 연속 알파벳 제거를 스택으로 해결했던 것을 응용해서 큐로 구현해서 스페이스가 아닌건 버리는 방식으로 해봄 #include using namespace std; class Solution { queue q; string output =""; public: string modify (string s) { for(int i=0; i> t; cin.ignore(); while(t--) { string s; getline(cin,s); Solution ob; cout [SAP/C++] Smallest Divisor leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/ Find the Smallest Divisor Given a Threshold - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 일단 문제를 이해하는 데 좀 걸렸다 나는 divisor라고 하길래, 약수인줄 알았는데 약수가 아니라 그냥..나누는 수 라는 의미였다 문제를 정의하면 다음과 같다. input : 2개 ( integer가 적힌 array.. [SAP/C++] K consecutive identical characters www.geeksforgeeks.org/reduce-the-string-by-removing-k-consecutive-identical-characters/ Reduce the string by removing K consecutive identical characters - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. www.geeksforgeeks.. [EPPER/15회 4번] 100만들기 //프로그래머스에서는 main함수 및 입출력문이 필요하지 않습니다. 대신 solution함수만 작성하면 됩니다. #include #include #include using namespace std; void solution(vector num){ int result=0; for(int i=0;i 이전 1 ··· 4 5 6 7 8 9 다음