전체 글
-
[LeetCode] 3. Longest Substring Without Repeating Characters c++Coding Test/LeetCode 2022. 12. 27. 15:53
문제 Given a string s, find the length of the longest substring without repeating characters. Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring. 문자 s가 주어지면, 반복되는 문자가 없는 가장 긴 하위 문자열의 길이를 찾는..
-
[LeetCode] 19. Remove Nth Node From End of List c++Coding Test/LeetCode 2022. 12. 27. 13:58
문제 Given the head of a linked list, remove the nth node from the end of the list and return its head. linked list에 뒤에서 n번째 노드를 제거하는 문제입니다. 문제 해결 class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode *fast = head, *slow = head; while(n--){ fast = fast->next; } if(!fast->next){ return head->next; } while(fast->next){ fast = fast->next; slow = slow->next; } slow->nex..
-
[LeetCode] 876. Middle of the Linked List c++Coding Test/LeetCode 2022. 12. 26. 18:45
문제 Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. 단일 링크로 이어져 있는 리스트에서 중간에 있는 노드를 구하는 문제입니다. 문제 해결 class Solution { public: ListNode* middleNode(ListNode* head) { ListNode *fast = head, *slow = head; while(fast){ fast = fast->next; if(fast){ fast = fast->next; } else{ break; } slow = slow->next; } re..
-
[LeetCode] 557. Reverse Words in a String III c++Coding Test/LeetCode 2022. 12. 26. 17:59
문제 Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" 문장에 있는 각 단어의 순서를 반대로 바꾸는 문제입니다. 문제 해결 class Solution { private: void parseString(string& str, vector& vec, const string& delimiter){ int pos = 0; while( (pos = str.find(delimite..
-
[LeetCode] 344. Reverse String c++Coding Test/LeetCode 2022. 12. 26. 16:49
문제 Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Input: s = ["h","e","l","l","o"] Output: ["o","l","l","e","h"] input으로 주어지는 벡터 s의 요소들의 순서를 반대로 뒤집는 문제입니다. 문제 해결 class Solution { public: void reverseString(vector& s) { reverse(s.begin(), s.end()); } }; 다른 풀이 class Solut..
-
[LeetCode] 167. Two Sum II - Input Array Is Sorted c++Coding Test/LeetCode 2022. 12. 26. 16:18
문제 Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1
-
[c++] std::partition_pointProgramming/c++ 2022. 12. 26. 14:04
1.함수 헤더 파일 #include 2.함수 원형 template ForwardIterator partition_point( ForwardIterator first, ForwardIterator last, UnaryPredicate pred); 조건을 충족하지 않는 지정된 범위의 첫 번째 요소를 반환합니다. 조건을 충족하는 요소가 그렇지 않은 요소 앞에 오도록 요소가 정렬됩니다. 3.return 값(반환 값) 반복자를 반환합니다. 테스트한 조건을 충족하지 않는 첫 번째 요소의 반복자, 반환하는 pred에서 last 반복자까지 찾을 수 없는 경우 4.예제 std::vector vec2 {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; auto point = std::partition_point(v..
-
[c++] std::stable_partitionProgramming/c++ 2022. 12. 24. 18:40
1.함수 헤더 파일 #include 2.함수 원형 template BidirectionalIterator stable_partition( BidirectionalIterator first, BidirectionalIterator last, UnaryPredicate pred ); template BidirectionalIterator stable_partition( ExecutionPolicy&& exec, BidirectionalIterator first, BidirectionalIterator last, UnaryPredicate pred); 참조된 범위는 유효해야 하고 모든 포인터는 역참조 가능해야 하며 시퀀스 내에서 처음 위치에서 증분하여 마지막 위치까지 도달할 수 있어야 합니다. pred는 사용..