본문 바로가기

Algorithm/Sorting

(28)
(C++) - LeetCode (easy) 1460. Make Two Arrays Equal by Reversing Subarrays https://leetcode.com/problems/make-two-arrays-equal-by-reversing-subarrays/description/ 간단 정렬 문제였습니다. 📕 풀이방법 📔 풀이과정 부분 배열을 뒤집어서 target배열로 만들려면 size와 원소가 같고 index만 다르면 됩니다. 1. target과 arr을 오름차순으로 정렬해줍니다. 2. 원소를 순회하며 모두 같은지를 비교합니다. 📔 정답 출력 | 반환 모두 같다면 true를 아니면 false를 반환합니다. 📕 Code 📔 C++ class Solution { public: bool canBeEqual(vector& target, vector& arr) { sort(target.begin(), target.end()); sor..
(C++) - LeetCode (easy) 1337. The K Weakest Rows in a Matrix https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 정렬을 사용해본 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 first는 행의 병사 수, second는 index를 저장할 vecotr pair soldiersCount를 선언해줍..
(C++) - LeetCode (easy) 1051. Height Checker https://leetcode.com/problems/height-checker/description/ Height Checker - LeetCode Can you solve this real interview question? Height Checker - A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the in leetcode.com 정렬을 이용한 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 heights를 복..
(C++, Rust) - LeetCode (easy) 977. Squares of a Sorted Array https://leetcode.com/problems/squares-of-a-sorted-array/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 정렬 해보는 문제였습니다. 📕 풀이방법 📔 풀이과정 각 원소를 제곱한 후 오름차순으로 정렬하면 됩니다.sort()함수를 적절히 사용해줍니다. 📕 Code 📔 C++ class Solution..
(C++) - LeetCode (easy) 628. Maximum Product of Three Numbers https://leetcode.com/problems/maximum-product-of-three-numbers/description/ Maximum Product of Three Numbers - LeetCode Can you solve this real interview question? Maximum Product of Three Numbers - Given an integer array nums, find three numbers whose product is maximum and return the maximum product. Example 1: Input: nums = [1,2,3] Output: 6 Example 2: Input: nums = [ leetcode.com 정렬 문제였습니다. ..
(C++) - LeetCode (easy) 561. Array Partition https://leetcode.com/problems/array-partition/description/ Array Partition - LeetCode Can you solve this real interview question? Array Partition - Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. leetcode.com 정렬 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 1. 오름차순으로 num..
(C++) - LeetCode (easy) 953. Verifying an Alien Dictionary https://leetcode.com/problems/verifying-an-alien-dictionary/description/ Verifying an Alien Dictionary - LeetCode Verifying an Alien Dictionary - In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the ali leetcode.com 정렬 문제였습니다. 📕 풀..
(C++) - LeetCode (easy) 88. Merge Sorted Array https://leetcode.com/problems/merge-sorted-array/ Merge Sorted 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 간단 정렬 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 nums1과 nums2를 하나로 먼저 합쳐줍니다. 📔 풀이과정 반환값이 없으므로 단순 오름차순으로 nums1을 정렬해주면 됩니다. 📕 Code 📔 C++ class Solution { public: void merge(vector& n..