알고리즘38 [프로그래머스] - 거리두기 확인하기 w/ Python 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr BFS 탐색과 값을 저장한 countArr을 통해 문제를 해결했다: 1. 모든 곳을 확인한다고 가정했을때 그 타일이 "P"값이라면? 2. 들어가서 주위에 있는 모든 칸 (위, 아래, 옆들)을 확인해서: - 같은 "P"라면 리턴 - "O"라면 countArr에 그 위치에서 + 1 3. 만약 "O"를 찾았는데 그 칸의 위치가 2 이상이라면 거리두기 실패로 False 리턴 4. 만약 다 탐색해서 올바른 자리에 있다면 "True'리턴 dx = [0, 0, -1, 1] dy = [1, -1, 0, 0] def sear.. 2024. 4. 17. [프로그래머스] - 방금그곡 w/ Python 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 재생된 시간, 노래 제목, 기억나는 음, 곡의 진짜음 4개로 푸는 문제 m에서 곡의 진짜 음, musicinfos에서 나머지 정보를 확인할 수 있다 이를 통해 확인해야될건 다음과 같다: 1. 기억나는 음들이랑 실제 음들이 같은지 -> 틀어진 시간 만큼 음을 늘려서 확인한다 2. 맞는 노래가 여러개면 가장 긴 시간을 보유한 노래가 무엇인지 해결한 부분: 1. #을 모두 소문자로 바꿔서 풀이를 했다 2. 들은 음과 실제 음악의 음들이 같다면 시간을 계산해 현재 가장 긴 시간을 비교 3. 맞는 음악이 1개도 없으면.. 2024. 4. 17. [Leetcode 215] - Kth Largest Element in an Array w/ Python Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting? 숫자가 들어가 있는 배열과 정수 k가 주어졌을때 정렬 없이 배열에서 k번째로 큰 숫자를 리턴하는 문제 https://leetcode.com/problems/kth-largest-element-in-an-array/description/ Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Outp.. 2024. 4. 16. [Leetcode 973] - K Closest Points to Origin w/ Python Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). [x, y]의 좌표가 들어있는 .. 2024. 4. 16. [Leetcode 1046] - Last Stone Weight w/ Python You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x 2024. 4. 16. [Leetcode 703] - Kth Largest Element in a Stream w/ Python Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class: 1. KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums. 2. int add(int val) Appends the integer val to the stream and returns the element representing the kth largest .. 2024. 4. 16. [Leetcode 51] - N-Queens w/ Python 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 may return the answer in any order. Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively. n x n크기.. 2024. 4. 16. [Leetcode 79] - Word Search Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. m x n의 배열이 주어지고 단어가 string으로 주어진다면 그 단어가 보드 배열에 있는지 확인하는 문제 상하좌우로 움직일 수 있고 이미 방문한 칸은 재방문이 불가능하다 https://leet.. 2024. 4. 13. [Leetcode 40] - Combination Sum II w/ Python Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. Each number in candidates may only be used once in the combination. Note: The solution set must not contain duplicate combinations. 숫자들로 이루어진 배열과 목표 (타겟) 숫자가 주어진다 배열들에 있는 숫자 합으로 목표에 도달할 수 있는 조합을 찾는 문제 배열에 있는 숫자는 한번씩 사용 가능하고 같은 조합.. 2024. 4. 13. 이전 1 2 3 4 5 다음 반응형