본문 바로가기

Algorithm/코드 풀이

(183)
LeetCode: 59번 (Spiral Matrix II) [JAVA] 문제 링크 https://leetcode.com/problems/spiral-matrix-ii/ Spiral Matrix II - LeetCode Can you solve this real interview question? Spiral Matrix II - Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: [https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg] Input: n = 3 O leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 n 크기를 바탕으로 n x n 크기의 이..
LeetCode: 56번 (Merge Intervals) [JAVA] 문제 링크 https://leetcode.com/problems/merge-intervals/ Merge Intervals - LeetCode Can you solve this real interview question? Merge Intervals - Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 우선 전체 int[][] intervals를 돌며..
LeetCode: 52번 (N-Queens II) [JAVA] 문제 링크 https://leetcode.com/problems/n-queens-ii/ N-Queens II - LeetCode Can you solve this real interview question? N-Queens II - The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return the number of distinct solutions to the n-queens leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 입력받은 n을 바탕으로 nxn 크기의 체스판(모두 '.'으로 초..
LeetCode: 53번 (Maximum Subarray) [JAVA] 문제 링크 https://leetcode.com/problems/maximum-subarray/ Maximum Subarray - LeetCode Can you solve this real interview question? Maximum Subarray - Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has t leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 두 개의 변수, minAcc, acc 선언 fo..
LeetCode: 51번 (N-Queens) [JAVA] 문제 링크 https://leetcode.com/problems/n-queens/ N-Queens - LeetCode Can you solve this real interview question? N-Queens - The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. You ma leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 입력받은 n을 바탕으로 nxn 크기의 체스판(모두 '.'으로 초기화),..
LeetCode: 50번 (Pow(x, n)) [JAVA] 문제 링크 https://leetcode.com/problems/powx-n/ Pow(x, n) - LeetCode Can you solve this real interview question? Pow(x, n) - Implement pow(x, n) [http://www.cplusplus.com/reference/valarray/pow/], which calculates x raised to the power n (i.e., xn). Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Inpu leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 x가 1.0이거나 n이 0이라면 1.0 반환 주어진 n이 음수라면, n..
LeetCode: 49번 (Group Anagrams) [JAVA] 문제 링크 https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Can you solve this real interview question? Group Anagrams - Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 String 문자열에 대한 정보를 가지는 ..
LeetCode: 48번 (Rotate Image) [JAVA] 문제 링크 https://leetcode.com/problems/rotate-image/ Rotate Image - LeetCode Can you solve this real interview question? Rotate Image - You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place [https://en.wikipedia.org/wiki/In-place_algorithm], which m leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 배열 속 특정 위치에 대해 90도 회전한 위치로 값을 이..