Playground/자바문제집 172

[백준] 1697번

ArrayIndexOutOfBoundsException 에러를 주의해서 코드를 작성해야 한다. public class Main { static int N, K; static int[] point = new int[100001]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); // 수빈이가 있는 위치 K = Integer.parseInt(st.nex..

[백준] 2178

public class Main { static int[] dx = {0, 1, 0, -1}; // 상 하 static int[] dy = {1, 0, -1, 0}; // 좌 우 static boolean[][] visited; // 방문한 곳인지 체크할 배열 static int[][] miro; // N x M 크기의 미로 static int n, m; // N 개의 줄에는 M 개의 정수로 미로가 이루어짐 public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTok..

[백준] 2748번

처음에 dp의 타입을 int 배열로 설정해서 실패했었다. 비록 입력값으로 주는 n의 값이 90 이하라고는 하지만 피보나치 수는 기하급수적으로 늘어나기 때문에 타입을 long으로 바꿔줬다. public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); // n번째 피보나치 수 long[] dp = new long[n + 1]; dp[0] = 0; dp[1] = 1; for (int i = 2; i

[프로그래머스] 올바른 괄호

와.. 오랜만에 stack 쓰려니까 메서드들이 기억 안 나서 블로그에서 찾아보고 풀었 import java.util.Stack; class Solution { boolean solution(String s) { boolean answer = true; Stack st = new Stack(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '(') { st.push('('); } else if (s.charAt(i) == ')') { if (st.isEmpty()) { answer = false; break; } else { st.pop(); } } } if(!st.isEmpty()) { answer = false; } return answer; ..