leetcode

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

LeetCode - Two Sum

class Solution { public: vector twoSum(vector& nums, int target) { vector answer (2); unsigned int length = nums.size(); for(int i = 0 ; i < length; i++) { unsigned int left = nums.at(i); for(int j = i+1 ; j < length; j++) { if((left + nums[j]) == target) { //answer.push_back(i); //answer.push_back(j); answer[0] = i; answer[1] = j; } } } return answer; } }; push_back 하면 런타임이 조금 더 걸림. (0.1초 정도?) ..

Archive

LeetCode - Reverse String

class Solution { public: void reverseString(vector& s) { if(!s.at(0)) return; int aPointer = 0; int bPointer = s.size()-1; while(aPointer

냉국
'leetcode' 태그의 글 목록