Algorithm/LeetCode

    2469. Convert the Temperature

    온도 단위 변환하기 https://leetcode.com/problems/convert-the-temperature/ Convert the Temperature - LeetCode Can you solve this real interview question? Convert the Temperature - You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit a leetcode.com 섭씨 온도를 나타내는 소수점 둘째 자리 섭씨로 반..

    1920. Build Array from Permutation

    순열로 이루어진 배열 재구성하는 문제 https://leetcode.com/problems/build-array-from-permutation/description/ 0부터 시작하는 순열로 이루어진 배열 nums가 주어진다. 이와 동일한 길이를 가지는 ans 배열을 반환하라. ans[i] = nums[nums[i]] class Solution { public int[] buildArray(int[] nums) { int len = nums.length; int[] ans = new int[len]; for(int idx = 0; idx < len; idx++){ ans[idx] = nums[nums[idx]]; } return ans; } }

    1929. Concatenation of Array

    배열 합치기 문제 https://leetcode.com/problems/concatenation-of-array/description/ 문제 파악 및 재정의nums라는 정수형 배열이 주어진다. nums의 2배의 길이를 가진 ans 배열을 반환하라. ans[i] == nums[i] and ans[i+n] == nums[i] import java.util.Arrays; class Solution { public int[] getConcatenation(int[] nums) { int n = nums.length; int[] ans = new int[n*2]; System.arraycopy(nums, 0, ans, 0, n); System.arraycopy(nums, 0, ans, n, n); return a..

    2319. Check if Matrix Is X-Matrix

    문제파악 및 재정의 X-Matrix 조건을 만족하면 True 아니면 False를 반환하라. 다음 조건이 모두 충족되는 경우 정사각형 행렬을 X-행렬이라고 합니다. 행렬의 대각선에 있는 모든 요소는 0이 아닙니다. 다른 모든 요소는 0입니다. 정사각형 행렬을 나타내는 n x n 크기의 2D 정수 배열 그리드가 주어지면 그리드가 X-매트릭스이면 true를 반환합니다. 그렇지 않으면 false를 반환합니다. 자료구조 및 알고리즘 선택 i j i j i j i j [0][0] 2 | [1][0] 0 | [2][0] 0 | [3][0] 4 [0][1] 0 | [1][1] 3 | [2][1] 5 | [3][1] 0 [0][2] 0 | [1][2] 1 | [2][2] 2 | [3][2] 0 [0][3] 1 | [1]..

    12. Integer to Roman

    문제 파악 및 재정의 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 로마 숫자를 정수로 변환시켜라 예를 들어, 2는 로마 숫자에서 II로 표기되며, 단지 두 개의 1을 더한 것입니다. 12는 XII로 표기되며, 간단히 X + II입니다. 숫자 27은 XXVII로 표기되며, 이는 XX + V + II입니다. 로마 숫자는 일반적으로 왼쪽에서 오른쪽으로 큰 순서로 씁니다. 그러나 4의 숫자는 IIII가 아닙니다. 대신 숫자 4는 IV로 씁니다. 1이 5보다 앞에 있기 때문에 빼면 4가 됩니다. 같은 원리가 IX로 쓰여진 숫자 9에도 적용됩니다. 빼기가 사용되는 경우는 6가지입니다. V(5)와 X(10) 앞에 I를 배치하여 4와 9를 만들 수 있습니다. X는 L(50)과 C(100) 앞에 배..

    278. First Bad Version

    문제 파악 및 재정의 n개의 버전이 주어지고 isBadVersion API가 제공된다. 첫 번째 불량 버전을 찾는 기능을 구현하며, API의 사용 횟수를 최소화 하라. 자료구조 및 알고리즘 선택 BinarySearch -> start와 end를 옮겨가며 mid의 위치를 조정하여 찾는 방식 구현 public class Solution extends VersionControl { public int firstBadVersion(int n) { int answer = 0; int start = 0; int mid = n/2; int end = n; if(n == 1) return 1; // 탈출 조건 while(true) { if(end == start) { answer = start; break; } if(..