934. Shortest Bridge
·
Algorithm/Leetcode
https://leetcode.com/problems/shortest-bridge/description/ You are given an n x n binary matrix grid where 1 represents land and 0 represents water.An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.You may change 0's to 1's to connect the two islands to form one island.Return the smallest number of 0's you must flip to con..
3223. Minimum Length of String After Operations
·
Algorithm/Leetcode
https://leetcode.com/problems/minimum-length-of-string-after-operations/description/?envType=daily-question&envId=2025-01-13 You are given a string s.You can perform the following process on s any number of times:Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i..
916. Word Subsets
·
Algorithm/Leetcode
https://leetcode.com/problems/word-subsets/description/?envType=daily-question&envId=2025-01-10 You are given two string arrays words1 and words2.A string b is a subset of string a if every letter in b occurs in a including multiplicity.For example, "wrr" is a subset of "warrior" but is not a subset of "world".A string a from words1 is universal if for every string b in words2, b is a subset of ..
542. 01 Matrix
·
Algorithm/Leetcode
https://leetcode.com/problems/01-matrix/description/?envType=problem-list-v2&envId=breadth-first-search    Input: mat = [[0,0,0],[0,1,0],[1,1,1]]Output: [[0,0,0],[0,1,0],[1,2,1]]  1에서부터 가장 가까운 0의 값을 배열에 저장해주면 되는 문제였다. 배열이 0이라면 큐에 삽입1이라면, -1로 초기화를 해준다 (거리 값 초기화)배열이 0인 곳에서부터 탐색을 하면서 거리가 -1인 곳을 계속해서 갱신해나가면 되는 문제였다.  정답 코드class Solution { int n, m; int [] dx = {1,0,-1,0}; int [] dy = {0,1,0..
78. Subsets
·
Algorithm/Leetcode
https://leetcode.com/problems/subsets/description/ Given an integer array nums of unique elements, return all possible subsets (the power set).The solution set must not contain duplicate subsets. Return the solution in any order. 배열이 주어질 때, 해당 배열의 모든 부분집합을 리턴하는 문제였다. (공집합 포함)해당 문제를 풀면서 느꼈던 것은 자바의 List 인터페이스 메서드에 대해서 잘 모르고 쓰고있구나 하는 생각이 들었다. 문제를 풀다가 List 형태에 Integer 값인 nums[i]를 추가했더니 error: incomp..
494. Target Sum
·
Algorithm/Leetcode
https://leetcode.com/problems/target-sum/description/?envType=daily-question&envId=2025-01-04 You are given an integer array nums and an integer target.You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate th..
1930. Unique Length-3 Palindromic Subsequences
·
Algorithm/Leetcode
https://leetcode.com/problems/unique-length-3-palindromic-subsequences/description/?envType=daily-question&envId=2025-01-04 주어진 문자열 s에서 길이가 3이고 중복되지 않은 팰린드롬의 갯수를 구하는 문제였다. 나는 백트래킹을 통해서 길이가 3인 모든 문자열을 찾아 Set에 넣어 중복되지 않은 문자열들을 구했다. 그 다음에, Set을 순회하며 해당 문자열이 팰린드롬인지 판단해주었다. 예제는 통과했지만, s의 길이가 10만이기 때문에 백트래킹을 시도했을 때 당연히 시초가 터졌다. 시간복잡도를 O(nlogn), 혹은 O(n) 이하로 줄일 방법을 찾아야 했다. 정답 풀이)class Solution { publ..
3286. Find a Safe Walk Through a Grid
·
Algorithm/Leetcode
https://leetcode.com/problems/find-a-safe-walk-through-a-grid/description/ You are given an m x n binary matrix grid and an integer health.You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1).You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive.Cells (i, j) with grid[i][j] = 1 are ..
조회수가 가장 많은 중고거래 게시판의 첨부파일 조회하기
·
Algorithm/프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/164671 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제USED_GOODS_BOARD와 USED_GOODS_FILE 테이블에서 조회수가 가장 높은 중고거래 게시물에 대한 첨부파일 경로를 조회하는 SQL문을 작성해주세요. 첨부파일 경로는 FILE ID를 기준으로 내림차순 정렬해주세요. 기본적인 파일경로는 /home/grep/src/ 이며, 게시글 ID를 기준으로 디렉토리가 구분되고, 파일이름은 파일 ID, 파일 이름, 파일 확장자로 구성되도록 출력해주세요. 조회수가 가장 높은 게시물은 하나만 존..
자동차 평균 대여 기간 구하기
·
Algorithm/프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/157342 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제CAR_RENTAL_COMPANY_RENTAL_HISTORY 테이블에서 평균 대여 기간이 7일 이상인 자동차들의 자동차 ID와 평균 대여 기간(컬럼명: AVERAGE_DURATION) 리스트를 출력하는 SQL문을 작성해주세요. 평균 대여 기간은 소수점 두번째 자리에서 반올림하고, 결과는 평균 대여 기간을 기준으로 내림차순 정렬해주시고, 평균 대여 기간이 같으면 자동차 ID를 기준으로 내림차순 정렬해주세요. 오답 코드SELECT ca..