본문 바로가기

Algorithm/알고리즘 문제풀이92

LeetCode 118(Pascal's Triangle, java) 0. 문제 https://leetcode.com/problems/pascals-triangle/ Pascal's Triangle - 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 1. 문제 설명 - 이 문제는 배열의 길이(numRows)가 주어진다. - 문제에서 이해를 돕기위해 그림이 주어진다. - 그림과 같은 방식으로, 주어진 배열의 길이만큼 파스탈의 삼각형을 생성하는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 판단 - 우선 결과를 저장할 이중 List를 .. 2022. 4. 13.
LeetCode 566(Reshape the Matrix, java) 0. 문제 https://leetcode.com/problems/reshape-the-matrix/ Reshape the Matrix - 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 1. 문제 설명 - 문제에서 이중 배열(mat), 행의 수(r), 열의 수(c)가 주어진다. - 주어진 이중 배열(mat)을 주어진 행(r)과 열(c)의 형태로 변환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 판단 - 가장 첫 번째로 파악해야 할 것은 주어진 이중 배.. 2022. 4. 13.
LeetCode 121(Best Time to Buy and Sell Stock, java) 0. 문제 https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 1. 문제 설명 - 문제에서 1개의 배열(prices)이 주어진다. - 각 배열의 원소는 매일의 주식 가격을 의미한다. ex) prices[0] = 첫째 날의 주식 가격, prices[1] = 둘째 날의 주식 가격 - 주식을 구매하고 .. 2022. 4. 12.
LeetCode 350(Intersection of Two Arrays 2, java) 0. 문제 https://leetcode.com/problems/intersection-of-two-arrays-ii/ Intersection of Two Arrays II - 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 1. 문제 설명 - 문제에서 2개의 배열(num1, num2)이 주어진다. - 두 배열의 원소를 비교하여 양쪽 배열에서 중첩되는 원소를 찾아, 배열의 형태로 반환하는 것이 문제의 핵심이다. - 다만, 한번 중복된 원소로 걸러진 원소는 다시 사.. 2022. 4. 12.
LeetCode 88(Merge Sorted Array, java) 0. 문제 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 1. 문제 설명 - 문제에서 2개의 배열(nums1, nums2)이 주어진다. - 이 2개의 배열은 오름차순으로 정렬되어 있다. - num1 배열에 num2 배열을 병합하는데, 병합 후 모든 원소가 오름차순으로 정렬되어 있어야 한다. - 문제에서 2개의 변수(m, n)가 주어진다... 2022. 4. 12.
LeetCode 1(Two Sum, java) 0. 문제 https://leetcode.com/problems/two-sum/ Two Sum - 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 1. 문제 설명 및 해결 전략 - 문제에서 배열(nums)과 찾는 값(target)이 주어진다. - 이 문제의 핵심은 주어진 배열의 요소 2개를 더하여 target을 만들 수 있느냐는 것이다. - 주어진 배열의 요소 2개를 더하여 target을 만들 수 있다면 두 요소의 index를 배열에 담아 결과로 반환한다. - 모.. 2022. 4. 11.
LeetCode 53(Maximum Subarray, java) 0. 문제 https://leetcode.com/problems/maximum-subarray/ Maximum Subarray - 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 1. 문제 설명 - 위의 문제의 핵심은 연속적인 배열 요소의 합 중에서 가장 큰 값을 찾는 것이다. - 이 문제에서 생각해야 할 것은 어떻게 연속적인 배열의 시작 요소를 어떻게 찾을 것이냐는 것이다. - 다음 예시를 보자. nums = [-2,1,-3,4,-1,2,1,-5,4] - 위의 .. 2022. 4. 11.
LeetCode 217(Contains Duplicate, java) 0. 문제 https://leetcode.com/problems/contains-duplicate/ Contains Duplicate - 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 1. 문제 설명 - 이 문제의 핵심은 배열 요소의 중복 유무를 검사하는 것이다. - 배열 요소의 중복 검사를 위해서는 for문을 이용해 배열의 요소를 HashSet에 삽입한다. - HashSet.add() 메서드는 boolean을 반환하기 때문에, 해당 메서드가 false를 반환하.. 2022. 4. 11.
백준 2750 파이썬 - 수 정렬하기(선택정렬) 1. 문제 링크 https://www.acmicpc.net/problem/2750 2750번: 수 정렬하기 첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다. 수는 중복되지 않는다. www.acmicpc.net 2. 나는 어떻게 생각했는가? # 백준 단계별 풀이 12단계 - 수 정렬하기 # https://www.acmicpc.net/problem/2750 # 선택정렬을 사용해서 풀어보자. from typing import List from sys import stdin input = stdin.readline def selection_sort(case: List[int]) -> List[int]:.. 2021. 8. 24.