Archive
2020.03.21
요즘 재귀에 꽂혀있음. class Solution { public: ListNode* swapPairs(ListNode* head) { if(!head) { return head; } ListNode* first= head; ListNode* second = head->next; ListNode* dummy = new ListNode(-1); dummy->next = first; ListNode* prev = dummy; while(second){ ListNode* temp = second->next; first->next = second->next; second->next = first; prev->next = second; prev = first; if(temp){ first = temp; secon..
Archive
2020.03.21
코딩인터뷰 단골손님. // 1부터 N까지의 합을 구하는 재귀함수 int sum(int N) { if (N
Archive
2020.03.12
#include #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; int i, j, k; for(int m = 0 ; m < commands.size(); m++) { i = commands[m][0]; j = commands[m][1]; k = commands[m][2]; vector temp (j - i + 1); for(int n = i ; i
Archive
2020.03.12
#include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; sort(participant.begin(), participant.end()); sort(completion.begin(),completion.end()); for(int i = 0 ; i < participant.size(); i++) { if(participant[i] != completion[i]) { return participant[i]; } } return answer; }