목록코테/프로그래머스 (33)
공부기록
문제 https://leetcode.com/problems/validate-binary-search-tree/ 코드 dfs import java.util.*; /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution {..
문제 https://programmers.co.kr/learn/courses/30/lessons/72415 코드 import java.util.*; class Solution { static int count = 0; static int min = 2000000000; int mv[][] = { {-1, 0}, {0, 1}, {1,0}, {0,-1} }; class Node{ int row; int col; int depth; public Node(int row, int col){ this.row = row; this.col = col; this.depth = 0; } public Node(int row, int col, int depth){ this.row = row; this.col = col; th..
문제 https://programmers.co.kr/learn/courses/30/lessons/72414 코드 class Solution { int makeIntTime(String time){ int hours = (time.charAt(0)-'0')*10+(time.charAt(1)-'0'); int minutes = (time.charAt(3)-'0')*10+(time.charAt(4)-'0'); int seconds = (time.charAt(6)-'0')*10+(time.charAt(7)-'0'); return hours*60*60 + minutes*60 + seconds; } String timeToStr(..
문제 https://programmers.co.kr/learn/courses/30/lessons/86053?language=cpp 코드 #include #include #include using namespace std; long long solution(int a, int b, vector g, vector s, vector w, vector t) { long long answer = 400000000000000; long long high = answer; long long low = 0; while(low = a+b && gSum >= a && sSum >= b 이렇게 해도 되는 이유는 다음과 같다. 먼저 금 요구량과 은 요구량을 합산한 양을 옮길 수 있는 지 찾는 것은 자명하다. 위 조건을 만족하..
문제 https://programmers.co.kr/learn/courses/30/lessons/81303 코드 import java.util.*; class Solution { class Node{ int idx; Node prev; Node next; public Node(int idx, Node prev, Node next){ this.idx = idx; this.prev = prev; this.next = next; } } public String solution(int n, int k, String[] cmd) { String answer = ""; StringBuilder sb = new StringBuilder("O".repeat(n)); Stack q = new Stack(); Node h..
문제 https://programmers.co.kr/learn/courses/30/lessons/86048# 코드 import java.util.*; class Solution { public int[] solution(int[] enter, int[] leave) { int[] answer = new int[enter.length]; Stack s1 = new Stack(); Stack s2 = new Stack(); HashSet his = new HashSet(); for(int i = enter.length-1; i>=0; i--) s1.add(enter[i]); for(int i=0; i
문제 https://programmers.co.kr/learn/courses/30/lessons/12907 코드 import java.util.*; class Solution { // static int answer = 0; // int dp[][] = new int[100001][100]; // void dfs(int[] money, int left, int threshold){ // if(left == 0){ // answer = (answer+1)%1000000007; // return; // }else{ // if(threshold = money[threshold]) // dfs(money, left-money[threshold], threshold); ..