목록정렬 (29)
N
https://edu.goorm.io/learn/lecture/33428/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%A8%BC%EB%8D%B0%EC%9D%B4-%EC%B1%8C%EB%A6%B0%EC%A7%80-%ED%95%B4%EC%84%A4/lesson/1669557/2%EC%A3%BC%EC%B0%A8-%EB%B3%B5%EC%8A%B5%EB%AC%B8%EC%A0%9C-3-%EC%B6%9C%EC%84%9D%EB%B6%80 goorm 구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다. goorm.co #include #include #include using namespace std; bool..
https://leetcode.com/problems/maximum-units-on-a-truck/ Maximum Units on a Truck - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정렬을 활용한 문제. 주어진 boxTypes 배열을 정렬하는데, boxTypes[1] 번째 요소의 내림차순으로 정렬을 해준다. 이후 for문을 이용해 truckSize가 채워지는 만큼 박스를 트럭에 채운다. 만약 truckSize - num이 0 이상이라면 모든 박스를 ..
https://leetcode.com/problems/non-decreasing-array/ Non-decreasing Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 nums 배열을 최대 1개의 원소만 바꿔서 오름차순 정렬이 가능한지 확인하는 문제. 변경 여부를 확인할 수 있는 flag인 isModified = false로 선언한다. for문으로 nums를 순회하는데, 인덱스는 1부터 시작한다. 만약 현재 방문한 원소가 이전 원소보다 값이 ..
https://leetcode.com/problems/last-stone-weight/ Last Stone Weight - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 오름차순 정렬을 이용. stones의 길이가 1일때까지 반복. stones를 오름차순으로 정렬한 후, 가장 뒤에 있는 두 개의 수를 각각 y, x에 저장한다. 만약 두 수가 같지 않다면 y - x 를 stones에 넣어주면 된다. 리턴값은 stones의 길이를 판단하여, 비어있다면 0, 그렇지 ..
https://programmers.co.kr/learn/courses/30/lessons/86491 코딩테스트 연습 - 8주차 [[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133 programmers.co.kr 주어진 sizes의 원소들을 오름차순으로 정렬한 후, w와 h의 최대값을 구해 곱하면 된다. #include #include #include using namespace std; int solution(vector sizes) { int wMax = 0; int hMax = 0; for(int i = 0; i < sizes.size(); i++){ sort(sizes[i..
https://programmers.co.kr/learn/courses/30/lessons/85002?language=cpp 코딩테스트 연습 - 6주차 복서 선수들의 몸무게 weights와, 복서 선수들의 전적을 나타내는 head2head가 매개변수로 주어집니다. 복서 선수들의 번호를 다음과 같은 순서로 정렬한 후 return 하도록 solution 함수를 완성해주세요 programmers.co.kr set과 map을 활용. weightSet은 주어진 weights를 new Set을 통해 중복없이 몸무게를 순서대로 나열하고 스프레드 연산자를 이용해 다시 배열로 만들었다. 이를 통해 복서들의 몸무게 순위를 매길 수 있으며, weightsMap에 key를 몸무게, value를 등수로 매겼다. 이후 이중 fo..
https://programmers.co.kr/learn/courses/30/lessons/85002?language=cpp 코딩테스트 연습 - 6주차 복서 선수들의 몸무게 weights와, 복서 선수들의 전적을 나타내는 head2head가 매개변수로 주어집니다. 복서 선수들의 번호를 다음과 같은 순서로 정렬한 후 return 하도록 solution 함수를 완성해주세요 programmers.co.kr 기본적인 STL을 모두 사용한 것 같다..ㅎㅎ vector, map, set, pair를 사용했으며, 정렬을 위한 algorithm 헤더까지 사용했다. 정렬의 우선순위가 승률 > 자신보다 무거운 사람을 이긴 수 > 자신의 몸무게 등수 > 자신의 인덱스 번호 로 되어 있다. 정렬을 하기 전, 복서들의 몸무게 ..
88. Merge Sorted Array You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate ..