본문 바로가기

Problem Solving

(152)
[Leetcode/C++] 206. Reverse Linked List /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) { ListNode *prev = nullptr; ListNode *curr = head; while(head != nullptr) { curr = curr->next;..
[Leetcode/C++] 496. Next Greater Element 1 class Solution { public: vector nextGreaterElement(vector& nums1, vector& nums2) { vector answer; for(int i = 0; i nums1[i]) {temp = *it; break;} } temp == 0 ? answer.push_back(-1) : answer.push_back(temp); } else { answer.push_back(-1); c..
[Leetcode/C++] 1021. Remove Outermost Parentheses class Solution { public: string removeOuterParentheses(string s) { int idx= 0; string answer = ""; for(int i = 0; i 1) answer.push_back(s[i]); idx--; } } return answer; } }; 그냥 O(n)으로 최대한 처리하고 싶어서 처음 괄호와 끝나는 괄호를 제외하고 모두 담도록 구현을 해보았습니다. 문제: https://leetcode.com/problems/remove-outermost-parenthes..
[백준/C++] 10828번 스택 #include #include #include using namespace std; int main() { int N, temp; cin >> N; string action; vector arr; for(int i = 0; i > action; if(action == "push") { cin >> temp; arr.push_back(temp); } else if(action == "top") { arr.empty() ? cout
[백준/C++] 8958번 OX퀴즈 #include using namespace std; int main() { int N, count = 0, answer = 0; string str; cin >> N; for(int i = 0; i > str; count = 0; answer = 0; for(int j = 0; j < str.length(); j++) { if(str[j] == 'O') count++; else count = 0; answer += count; } cout
[백준/C++] 5622번 다이얼 #include using namespace std; int main() { string answer = "ADGJMPTW"; string str; int count = 0; cin >> str; for(int i = 0; i < str.length(); i++) { for(int j = 0; j < answer.length(); j++) { if(str[i] < answer[j]) break; count++; } count+=2; } cout
[백준/C++] 5598번 카이사르 암호 #include using namespace std; int main() { string answer; cin >> answer; for(int i = 0; i < answer.length(); i++) { answer[i] < 'D' ? answer[i]+=23 : answer[i]-=3; } cout
[백준/C++] 4659번 비밀번호 발음하기 #include #include #include #include #include #include #include using namespace std; int main() { int answer = 0; while(true) { int is_vowel = 0, novowel = 0, vowel = 0, idx = 0, j = 0; string str = ""; cin >> str; if(str == "end") break; for(j = 0; j < str.length(); j++) { switch(str[j]) { case 'a' : case 'e' : case 'i' : case 'u' : case 'o' : is_vowel++; vowel++; novowel = 0; break; default : v..