C++ ] leetCode 143 - Reorder List
리트코드 143번 문제 You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … You may not modify the values in the list's nodes. Only nodes themselves may be changed. Example 1: Input: head = [1,2,3,4] Output: [1,4,2,3] Example 2: Input: head = [1,2,3,4,5] Output: [1,5,2..
2024. 5. 8.
C++ ] leetCode 1029 - Two City Scheduling
리트코드 1029 문제 A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti. Return the minimum cost to fly every person to a city such that exactly n people arrive in each city. Example 1: Input: costs = [[10,20],[30,200],[400,50],[30,20]] Outp..
2024. 4. 21.
C++ ] std::iota 사용법
처음엔 itoa의 오타인 줄 알았다. std::iota는 헤더에 정의된 C++ 표준 라이브러리 함수로 배열이나 컨테이너에 연속적 숫자를 할당한다. 시작 반복자, 종료 반복자, 그리고 초기 값의 세 개의 매개변수를 받는다. #include #include std::vector v(10); std::iota(v.begin(), v.end(), 0); // v는 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}로 초기화됨 for 반복문을 사용해서 동일한 작업을 수행할 수 있다. 둘 다 O(n) 시간 복잡도를 가지며 유의미한 성능차이는 없을 것 같다. std::vector v(10); for(int i = 0; i < v.size(); ++i) { v[i] = i; }
2024. 4. 19.