recursion

Archive

LeetCode - Swap Nodes in Pairs

요즘 재귀에 꽂혀있음. 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

Recursion (재귀)

코딩인터뷰 단골손님. // 1부터 N까지의 합을 구하는 재귀함수 int sum(int N) { if (N

냉국
'recursion' 태그의 글 목록