Algorithm
2413. Smallest Even Multiple
https://leetcode.com/problems/smallest-even-multiple/ Smallest Even Multiple - LeetCode Can you solve this real interview question? Smallest Even Multiple - Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. Example 1: Input: n = 5 Output: 10 Explanation: The smallest multiple of both 5 and leetcode.com Given a positive integer n, return the smal..
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..
신규 아이디 추천
문제 파악 및 재정의 아이디 규칙에 맞지 않는 아이디를 입력하였을 때, 입력된 아이디와 유사하며 규칙에 맞는 아이디 추천 아이디 길이 3 ~ 15 아이디는 알파벳 소문자, 숫자, 빼기, 밑줄, 마침표 문자만 사용가능 마침표는 처음과 끝에 사용할 수 없으며 연속으로 사용 불가 단계 1. 소문자 치환 2. 알파벳 소문자, 숫자, -, _, . 제외한 모든 문자 제거 3. 마침표(.) 2번 이상 연속된 부분을 하나의 마침표로 치환 4. 마침표(.)가 처음이나 끝에 위치한다면 제거 5. 빈 문자열이라면 "a"를 대입 6. 길이가 16자 이상이라면 첫 15문자를 제외한 나머지 문자들을 모두 제거 만약 제거 후 마침표(.)가 끝에 위치한다면 끝에 위치한 마침표 문자를 제거 7. 길이가 2자 이하라면 마지막 문자를 ..
혼자서 하는 틱택토
문제파악 및 재정의 틱택토 -> O X O X O X -> 가로, 세로, 대각선으로 완성되면 승리 3칸이 완성되지 않는다면 무승부 1.차례에 맞지 않는 진행 2.승리 후 게임 진행 O, X, .(빈칸)으로 구성된 board를 참조하여 규칙을 지킨 틱택토일 경우 1 아니라면 0을 반환 O . X . O . . . X 선,후공 세트 + 3칸으로 게임을 끝냈을 때 진행 여부 판별 O나 X가 가로, 세로, 3칸을 완성했는가? -> 3칸 완성 이후 게임의 진행? -> 가로 [0][0] [0][1] [0][2] 세로 [0][0] [1][0] [2][0] 대각선 -> [0][0] [1][1] [2][2] i == j or [2][0] [1][1] [0][2] -> i + j == board.length -1 자료구조..