목록CSE/baekjoon & swexpert (53)
한 걸음 두 걸음
완성한 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { String str = "()))((()"; System.out.println(recurCheck(str)); } static //올바른 괄호 문자열인지 검사하는 함수 boolean isRight(String str) { int count = 0; boolean isRight = true; for(int i = 0 ; i < str.length(); i++) { if(str.charAt(i) == '(') count++; else count--; if(count < 0 ) { isRight = false; } } return..

2019년도 블라인드테스트에 나왔던 1번 문자열 압축 문제 JAVA풀이 문제 : https://programmers.co.kr/learn/courses/30/lessons/60057?language=java class Solution { public int solution(String s) { String exStr = s; String bufStr = ""; String resultStr = ""; int bufCount = 1; int resultLen = exStr.length(); int resultCount = resultLen; for(int i = 1 ; i 버퍼와 값이 다르므로 resultString = "aa" 추가해줌 bb buf = "aa" -> 버퍼와 값이 다르므로 resultStr..
소수찾기 복잡도 개선한 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testCase = sc.nextInt(); int result = 0; for(int i = 0 ; i < testCase ; i++) { if(isDecimal(sc.nextInt())) result++; } System.out.print(result); sc.close(); } public static boolean isDecimal(int num) { if(num == 1) return false; for(int i = 2 ; i*i
밣밢따맣밤밥따밦따밙다맣밦밡따박따맣밦밡따반따맣받밚따밠따밦다맣밣밤따맣밞밡따밦다맣밬발따밠따밦다맣받밚따밝따밟다맣밦밟따박따맣밙발따밨따맣밦발다밬따맣하
에러코드 : java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0 원인 : String[] tokenStrPlus = str.split("+"); 해결 : String[] tokenStrPlus = str.split("\\+"); 전체코드 : import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String getEx = sc.nextLine(); String[] tokenStrMinus = getEx.split("-"); ..
import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Queue queue = new LinkedList(); int testCase = sc.nextInt(); int pushValue = 0; for(int i = 0 ; i < testCase; i++) { String command = sc.next(); if(command.equals("push")) { pushValue = sc.nextInt(); queue.add(pushValue); } else { switch(command) { case "pop":..
import java.util.*; import java.lang.*; public class Main { static boolean[][] board = new boolean [50][50]; static int[][] dir = {{-1, 0},{0, -1},{0, 1},{1, 0}}; static int row,col; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cnt; //입력받을 배추갯수 int result = 0; //결과값 int testCase = sc.nextInt(); //테스트케이스만큼 for(int test = 0; test < testCase; test++) { row = sc...
import java.io.IOException; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.util.*; import java.lang.*; class Pair { int pos; int cnt; public Pair(int n, int c) { pos = n; cnt = c; } } public class Main { static boolean[] visited = new boolean [100001]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); Queue q = new LinkedList(); int n = sc..