/users
/posts
/slides
/apps
/books
mysetting
/users
/posts
/slides
/apps
/books
3:26 5/30
velog.io
3:26
velog.io
삶도 재입학이 되나요?
https://velog.io/@dongha1992
글과 코드와 사람에 관해 생각합니다.
저작도구: velog
최종 피드 수집: 2024-10-22 23:17
전체 (114)
1M
99클럽 코테 스터디 39일차 - DP
문제
Best Time to Buy and Sell Stock
풀이
최소값과 최대값 차이가 가장 컸을 때를 구하면 된다
최대 10의 5승까지라서 O(n)으로 풀어야 한다
순회를 하면서 min과 max를 동시에 구하기
코드
clas
0
0
0
읽기모드
1M
99클럽 코테 스터디 38일차 - DP
문제
N-th Tribonacci Number
풀이
피보나치인데 3개의 수에 대한 피보나치
재귀 과정에서 중복이 발생하므로 memo를 해줘야 한다
코드
class Solution {
private int[] memo;
0
0
0
읽기모드
1M
99클럽 코테 스터디 37일차 - DP
문제
Min Cost Climbing Stairs
풀이
시작점을 0 또는 1에서 고를 수 있다
step은 한 번 또는 두 번 갈 수 있다.
이 중 최소 비용으로 배열에 끝에 도달해야 한다.
배열을 순회할 때마다 최소 비용을 골라서
0
0
0
읽기모드
1M
99클럽 코테 스터디 37일차 - 그리디
문제
Assign Cookies
풀이
정렬 후 두 배열을 비교하면 된다
코드
class Solution {
public int findContentChildren(int[] g, int[] s) {
Array
0
0
0
읽기모드
1M
99클럽 코테 스터디 37일차 - 완전탐색
문제
Longest Palindrome
풀이
가장 긴 회문을 찾으면 된다
문자열을 정렬하고 hashSet으로 같은 짝을 찾음. 홀수의 경우 +1
코드
class Solution {
public int longestPalin
0
0
0
읽기모드
1M
99클럽 코테 스터디 36일차 - 완전탐색
문제
적어도 대부분의 배수
풀이
하라는대로 하면 된다!
코드
import java.util.Scanner;
public class Main {
public static void main(String[] args){
0
0
0
읽기모드
1M
99클럽 코테 스터디 35일차 - 완전탐색
문제
적어도 대부분의 배수
풀이
주어진 5개의 자연수 중 적어도 3개로 나누어 떨어지는 가장 작은 수를 구해야함
즉, 3개 조합의 최소공배수의 최소값
for문 3번 중첩해서 순회하면서 모든 경우 구하고 각각 최소공배수도 구해줌
코
0
0
0
읽기모드
1M
99클럽 코테 스터디 34일차 - dfs
문제
영역 구하기
풀이
영역 개수 만큼 순회하며 주어진 좌표들을 기준으로 board[][]에 1을 채움
board를 순회하면서 dfs로 영역의 개수를 카운팅
코드
import java.util.*;
public class Main
0
0
0
읽기모드
1M
99클럽 코테 스터디 33일차 - dfs
문제
양 한마리... 양 두마리...
풀이
dfs 순회하며 '#'을 카운팅
코드
public class Main {
static int h, w;
static char[][] board;
static b
0
0
0
읽기모드
2M
99클럽 코테 스터디 32일차 - bfs
문제
Number of Good Leaf Nodes Pairs
풀이
두 말단 노드의 거리가 distacne 이하인 쌍의 개수를 찾는 문제
주어진 Tree를 Graph로 구성하고, leaves를 구해놓은다
구한 leaves 를 순회
0
0
0
읽기모드
2M
99클럽 코테 스터디 31일차 - bfs
풀이
이차원 배열 순회하면서 > 0 인 x, y를 기점으로 8면을 dfs로 탐색함
visited로 방문하지 않은 곳만 탐색
코드
public class Main {
static int r, c;
static int
0
0
0
읽기모드
2M
99클럽 코테 스터디 30일차 - bfs
풀이
백준 뭐지.. 백준 처음 해보는데 플랫폼 자체가 너무 어렵다.. 문제 이해하는 것도 오래 걸림..
input을 어떻게 넣어야 하는지 몰라서 지피티 참고함
코드
import java.util.*;
public class Mai
0
0
0
읽기모드
2M
99클럽 코테 스터디 29일차 - 이진탐색
Arranging Coins
풀이
n에서 차감하면서 만들 수 최대 row를 만든다.
이진탐색의 경우, mid 값을 뽑아 mid까지 모든 수를 더해 n과 비교한다. n보다 작을 경우, 해당 row는 모두 채울 수 있으므로 low를
0
0
0
읽기모드
2M
99클럽 코테 스터디 28일차 - 이진탐색
Missing Number
풀이
연속된 숫자 중 없는 수를 찾으면 된다
n이 10의 4제곱까지 있으므로 이진탐색으로 수행
아이디어는 nums[i] != i
코드
class Solution {
public int mi
0
0
0
읽기모드
2M
99클럽 코테 스터디 27일차 - 큐
프로세스
풀이
prioty와 index를 queue에 저장
queue를 순회하면서 현재 prioty보다 더 큰 우선수위가 있는지 찾는다 (위 과정은 최대 힙으로 했으면 간단했을 듯)
더 큰 우선순위가 있다면 현재 queue에서 꺼
0
0
0
읽기모드
2M
99클럽 코테 스터디 27일차 - 완전탐색
문제
공원 산책
풀이
주어진 배열에 따라 좌표를 이동시키는 것.
제한 조건으로는 'X'를 만나면 해당 move는 상쇄된다.
동서남북에 따라 x, y의 움직임을 지정한다
시작점이 항상 [0,0]이 아니므로 시작점을 먼저 구한다
r
0
0
0
읽기모드
2M
99클럽 코테 스터디 26일차 - 완전탐색
문제
바탕화면 정리
풀이
중첩 순회를 하면서 "#"를 찾으면 시작점과 끝점을 업데이트한다.
코드
lass Solution {
public int[] solution(String[] wallpaper) {
in
0
0
0
읽기모드
2M
99클럽 코테 스터디 25일차 - 그래프
문제
Find if Path Exists in Graph
풀이
인접리스트 후 source부터 destination까지 도달하는지 체크하는 문제
bfs로 탐색하면 된다.
코드
class Solution {
public bo
0
0
0
읽기모드
2M
[프로그래머스] 가장 먼 노드
문제
[가장 먼 노드]
풀이
주어진 배열을 인접리스트로 구성한다
queue에서 노드를 꺼내고 w와 max값을 비교해서 업데이트
bfs로 노드를 순회하면서 w를 증가시킴
중복 방문을 피하기 위해 visited로 검사
각 노드마다 1
0
0
0
읽기모드
2M
99클럽 코테 스터디 23일차 TIL - 그래프
문제
Find Center of Star Graph
풀이
중심에 있는 노드를 찾는 것
중심 노드는 모든 노드들과 간선이 존재한다.
연결리스트를 만들어서 for문 순회하면서 모든 노드들과 간선이 존재하는 즉, edges.lengt
0
0
0
읽기모드
About
Badge
Contact
Activity
Terms of service
Privacy Policy