분류 전체보기
-
[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는 사용..
-
[LeetCode] 283. Move Zeroes c++Coding Test/LeetCode 2022. 12. 24. 17:54
문제 Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] 문제 해결 처음에는 벡터 원소에 0이 있으면 삭제하는 문제인 줄 알았다. remove_if() 함수를 사용해서 0이라면 삭제하는 코드를 작성했다. class Solution { public: static bool oper(const int& a){ if( a == 0){ r..
-
[LeetCode] 606. Construct String from Binary Tree c++Coding Test/LeetCode 2022. 12. 24. 14:58
문제 Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree. Input: root = [1,2,3,null,4] Output: "1(2()(4))(3)" Explanation: Almost the same as the first ex..