본문 바로가기

JavaScript/Leetcode9

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 puzzle.Example 1:Input: n = 4 Output: 2 Explanation: There are two distinct solutions to the 4-queens puzzle as shown.Example 2:Input: n = 1 Output: 1  Constraints:1 풀이파이썬으로 하루종일 답보고 분석했던 문제다.같은 행과 대.. 2024. 10. 24.
Generate Parentheses (Medium) 문제Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1:Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"]Example 2:Input: n = 1 Output: ["()"]  Constraints:1  풀이dp를 이용해서 전에 썼던 배열에 추가하기. 우선 dp 배열을 []로 초기화 하자 그리고 dp[0]에 빈 문자열 "" 추가 let dp = new Array(n + 1).fill(0).map(() => []);dp[0].push("");  그런 다음 n-1 들의 조합에 ()를 더해주자.. 2024. 10. 23.
132 Pattern (Medium) 문제Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i Return true if there is a 132 pattern in nums, otherwise, return false.Example 1Input: nums = [1,2,3,4] Output: false Explanation: There is no 132 pattern in the sequence. Example 2: Input: nums = [3,1,4,2] Output: true Explanation: There is a 132 pattern in the sequence.. 2024. 10. 23.
Trapping Rain Water (Hard) 문제Given n non negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.  Example 2:Input.. 2024. 10. 23.
Group Anagrams (Medium) 문제Given an array of strings strs, group the anagramsntogether.  You can return the answer in any order. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Explanation: There is no string in strs that can be rearranged to form "bat". The strings "nat" and "tan" are anagrams as they can be rearranged to form each other. The strings "a.. 2024. 9. 28.
Container With Most Water (Medium) 문제You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Example 1:Input: heigh.. 2024. 9. 27.