기본 콘텐츠로 건너뛰기

1월, 2023의 게시물 표시

코딩 테스트 - TreeHeight

public class TreeHeight_230131 { public static void main (String[] args) { System. out .println( solution (T)) ; } public static int solution (Tree T) { return height (T) ; } // 재귀로 높이 얻음 public static int height (Tree T) { if (T == null ){ // T 자체가 비어버리면 -1 처리 ( 안해주면 오류남 ) return - 1 ; } else { // 왼쪽 트리와 오른쪽 트리의 최대 높이를 구하고 , // +1 을 더한 값을 return 해줌 ( 현재 높이까지 더해줘야 함 ) return Math. max ( height (T.l) + 1 , height (T.r) + 1 ) ; } } public int solution_ 재귀로안풀면 (Tree T) { //https://github.com/jlhuang/codility-lessons/blob/master/lesson%2099%20:%20Future%20training/TreeHeight/Solution_Non_Recurse.java // 큐는 트리의 각각 수준 노드를 가지고 있다 . ArrayList<Tree> queue = new ArrayList<Tree>() ; queue.add(T) ; int height = - 1 ; while (queue.size() != 0 ) { height++ ; // 현재 레벨의 노드의 수

코딩 테스트 - StrSymmetryPoint

public class StrSymmetryPoint_230130 { public static void main (String[] args) { String S = "racecar" ; //String S = "x"; System. out .println( solution (S)) ; } public static int solution (String S) { if ((S.length() & 1 ) == 0 ) { return - 1 ; } int answer = S.length() / 2 ; for ( int i = answer , j = answer ; j >= 0 ; i++ , j--) { //i j 둘 다 옵션 넣을 수 있음 //System.out.println(i + " ㅇㅅㅇ " + j); if (S.charAt(i) != S.charAt(j)) { return - 1 ; } } return answer ; } public static int solution2 (String S) { if (S.length()% 2 != 0 ){ // 홀수 경우만 처리 if (S.length() == 1 ){ // 길이가 1 인 경우 0 return 0 ; } else if (S.length() == 3 ){ // 길이가 3 인 경우 앞 뒤 같으면 0 if (S.charAt( 0 ) == S.charAt( 2 )

코딩 테스트 - ThreeLetters

public class ThreeLetters_230129 { public static void main (String[] args) { int A = 5 ; int B = 3 ; //System.out.println(solution(A,B)); A = 3 ; B = 3 ; //System.out.println(solution(A,B)); A = 1 ; B = 4 ; System. out .println( solution (A , B)) ; } public static String solution ( int A , int B) { int ALen = A ; int BLen = B ; StringBuilder sb = new StringBuilder() ; int cnt = 0 ; String answer = lenSolve (ALen , BLen , sb) ; return answer ; } private static String lenSolve ( int aLen , int bLen , StringBuilder sb) { int max = aLen ; int min = bLen ; String maxStr = "a" ; String minStr = "b" ; int cnt = 0 ; if (aLen < bLen) { max = bLen ; min = aLen ; maxStr = "b" ; minStr = "a" ; } while ( true

코딩 테스트 - CountConformingBitmasks

public class CountConformingBitmasks_230128 { public static void main (String[] args) { int A = 1073741727 ; int B = 1073741631 ; int C = 1073741679 ; System. out .println( solution (A , B , C)) ; } public static int solution ( int A , int B , int C) { int answer = 0 ; String aStr = Integer. toBinaryString (A) ; String bStr = Integer. toBinaryString (B) ; String cStr = Integer. toBinaryString (C) ; answer = checkBit (aStr)+ checkBit (bStr)+ checkBit (cStr) ; answer -= checkBit (Integer. toBinaryString (A|B)) ; answer -= checkBit (Integer. toBinaryString (A|C)) ; answer -= checkBit (Integer. toBinaryString (B|C)) ; answer += checkBit (Integer. toBinaryString (A|B|C)) ; return answer ; } private static int checkBit (String number){ int count= 0 ; for ( int i = 0 ; i < number.leng

코딩 테스트 - ParityDegree

public class ParityDegree_230127 { public static void main (String[] args) { int N = 24 ; System. out .println( solution (N)) ; } public static int solution ( int N) { int answer = 0 ; while (N % 2 == 0 ) { N = N / 2 ; answer++ ; } return answer ; } } Easy 등급의 클라스...

코딩 테스트 - FirstUnique

import java.util.Arrays ; import java.util.HashMap ; import java.util.Map ; import java.util.OptionalInt ; public class FirstUnique_230126 { public static void main (String[] args) { System. out .println( "sout + Ctrl + Space" ) ; System. out .println( "so + tab" ) ; // 생각보다 이거 실행하는데 속도가 느림 ... // 파일명 바꾸기 - shift + f6 int [] A = { 4 , 10 , 5 , 4 , 2 , 10 } ; //int [] A = {6,4,4,6}; System. out .println( solution (A)) ; } public static int solution ( int [] A){ Map<Integer , Integer> map = new HashMap<>() ; for ( int i : A) { int 임시값 = map.getOrDefault(i , 0 ) ; map.put(i , ++ 임시값 ) ; } for ( int i : A) { if (map.get(i) == 1 ) { return i ; } } return - 1 ; } public static int solution2 ( int [] A) { int 정답 = - 1 ; int 최대값 = Arrays. stream (A).max().getAs

개발 공부 - JETBRAINS ToolBox 및 IntelliJ 설치 (학생용 / 교육용)

 요새 쓰는 VSCode 대신 다시 인텔리J를 쓰려고 교육용을 받아본다. https://www.jetbrains.com/ko-kr/lp/general-leaflets/students/ 여기서 신청 링크 들어가면 된다. https://www.jetbrains.com/shop/eform/students/ 여기임. 학생용 계정 있으면 사용 가능하다. 저 링크 들어가서 어떻게 잘 하다 보면 (가입 하고 어쩌구 하면 된다.) https://account.jetbrains.com/licenses 이 링크에 들어갈 수 있는데, 여기서 다운 받으면 된다. 나는 ToolBox 다운받아서 거기서 받으려고 한다. (버전 관리도 할 겸) https://www.jetbrains.com/toolbox-app/ 아무튼 깔아서 잘 쓰면 됨... 링크 타고 타고 가면 된다. 바뀐 것 좀 보려고 교육 과정 좀 밟아보려고 한다. 230421 추가 :  잘 쓰다가 이직으로 인해서 다시 Spring STS를 쓰게 되어 다소 하향된 환경이 되었다. 이미 좋은 걸 맛봐서 이제는 이클립스가 💩💩 같은 것이다.

코딩 테스트 - ParkingBill

class ParkingBill_230125 {     public static void main ( String [] args ) {         String E = "10:00" ;         String L = "13:21" ;         System . out . println ( solution ( E , L ));     }     public static int solution ( String E , String L ) {         int answer = 2 ;         //주차장 입장료 : 2         //처음 한시간 : 3         //그 다음부터는 : 4         /*          * 10:00~13:21          * 2          * ~ 11:00 - 3 = 5          * ~ 12:00 - 4 = 9          * ~ 13:00 - 4 = 13          * ~ 13:~  - 4 = 17          */         String [] ESplit = E . split ( ":" );         String [] LSplit = L . split ( ":" );         int 출발시 = Integer . parseInt ( ESplit [ 0 ]);         int 출발분 = Integer . parseInt ( ESplit [ 1 ]);         int 이별시 = Integer . parseInt ( LSplit [ 0 ]);         int 이별분 = Integer . parseInt ( LSplit [ 1 ]);         if (( 출발분 - 이별분 ) < 0 ){             이별시 ++;         }         int 시간 = 이별시 - 출발시 ;         if ( 시간

코딩 테스트 - SlalomSkiing

import java . util . Arrays ; public class SlalomSkiing_230124 {     public static void main ( String [] args ) {         int [] A = { 15 , 13 , 5 , 7 , 4 , 10 , 12 , 8 , 2 , 11 , 6 , 9 , 3 };         System . out . println ( solution ( A ));     }               public static int solution ( int [] A ) {         long 최대값 = Arrays . stream ( A ). max (). getAsInt ();         long [] 방향바꾸기용 = new long [ A . length * 3 ];                 for ( int i = 0 ; i < A . length ; i ++){             방향바꾸기용 [ i * 3 ] = 최대값 * 2 + A [ i ] + 1 ;             방향바꾸기용 [ i * 3 + 1 ] = 최대값 * 2 - A [ i ] + 1 ;             방향바꾸기용 [ i * 3 + 2 ] = A [ i ];         }           /*         for(long l : 방향바꾸기용){             System.out.println("\t" + l);         }                 46                 16                 15                 44                 18                 13                 36                 26                 5                 38                 24              

코딩 테스트 - 오픈채팅방

package programmers ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; public class 오픈채팅방_230123 {     public static void main ( String [] args ) {         String [] record = {             "Enter uid1234 Muzi" ,             "Enter uid4567 Prodo" ,             "Leave uid1234" ,             "Enter uid1234 Prodo" ,             "Change uid4567 Ryan"         };         System . out . println ( Arrays . toString ( solution ( record )));     }     public static String [] solution ( String [] record ) {         ArrayList < String > 로그 = new ArrayList <>();         HashMap < String , String > map = new HashMap <>();                 for ( int i = 0 ; i < record . length ; i ++){             String [] temp = record [ i ]. split ( " " );             String 명령어 = null ;             String 아이디 = null ;             String 이름 = null ;        

코딩 테스트 - FloodDepth

public class FloodDepth_230123 {     public static void main ( String [] args ) {         int [] A = { 1 , 3 , 2 , 1 , 2 , 1 , 5 , 3 , 3 , 4 , 2 };         System . out . println ( solution ( A ));     }     /*         당신은 산악 호수가 있는 지역을 조사하는 지질학자 친구를 돕고 있습니다.         최근 폭우로 인해 이 호수가 범람했으며 수위가 최고점에 도달했습니다.         당신의 친구는 이 호수의 가장 깊은 부분의 최대 깊이를 알고 싶어합니다.         문제를 2차원 차원으로 단순화합니다.         전체 풍경은 작은 블록으로 나눌 수 있으며 길이 N의 배열 A로 설명할 수 있습니다.         A의 각 요소는 블록의 암석 바닥의 고도(즉, 물이 전혀 없을 때 이 블록의 높이)입니다.         강우 후 모든 저지대(즉, 양쪽에 더 높은 블록이 있는 블록)는 가능한 한 많은 물을 보유하고 있습니다.         이 전체 지역이 침수된 후 최대 수심을 알고 싶습니다.         이 영역 외부의 고도는 0이고 외부 영역은 무한한 양의 물을 수용할 수 있다고 가정할 수 있습니다.         예를 들어 다음과 같은 어레이 A를 고려하십시오.                 A[0] = 1             A[1] = 3             A[2] = 2             A[3] = 1             A[4] = 2             A[5] = 1             A[6] = 5             A[7] = 3             A[8] = 3             A[9] = 4             A[10] = 2         다음 그림은 홍수가 난 후의 풍경을 보여줍니다.         회색 영역은 위

코딩 테스트 - 타겟 넘버

package programmers ; public class 타겟넘버_230122 {     public static void main ( String [] args ) {         int [] numbers = { 1 , 1 , 1 , 1 , 1 };         int target = 3 ;         System . out . println ( solution ( numbers , target ));     }     static int answer = 0 ;     public static int solution ( int [] numbers , int target ) {         dfs ( numbers , target , 0 , 0 );         return answer ;     }         // 깊이 우선 탐색     public static void dfs ( int [] numbers , int target , int 깊이 , int 총합 ){         if ( 깊이 == numbers . length ){             //깊이를 배열 길이 끝까지 탐색 (마지막 노드)             if ( target == 총합 ){                 answer ++;             }         } else {                         int 더하기 = 총합 + numbers [ 깊이 ]; //총합 : 노드 값 더하고 다음 깊이 탐색             int 빼기 = 총합 - numbers [ 깊이 ]; // 총합 : 노드 값 빼고 다음 깊이 탐색             dfs ( numbers , target , 깊이 + 1 , 더하기 );             dfs ( numbers , target , 깊이 + 1 , 빼기 );         }     } } 오랜만에 dfs!

코딩 테스트 - LongestPassword

설날 기념 아래부터 풀기 import java . util . regex . Pattern ; public class LongestPassword_230122 {     public static void main ( String [] args ) {         String s = "test 5 a0A pass007 ?xy1" ;         System . out . println ( solution ( s ));     }           public static int solution ( String S ) {         int answer = - 1 ;         String [] arr = S . split ( " " );         //문자열 S는 공백을 제거하고 분할 하여 단어 로 나눌 수 있습니다.                 for ( int i = 0 ; i < arr . length ; i ++){             /*                         영숫자 문자( a − z , A − Z , 0 − 9 )만 포함해야 합니다.                 짝수의 문자가 있어야 합니다.                 홀수의 자릿수가 있어야 합니다.             */             String [] temp = arr [ i ]. split ( "" );             int 짝수문자개수 = 0 ;             int 홀수자리수 = 0 ;             boolean 특수문자체크 = true ;             for ( int j = 0 ; j < temp . length ; j ++){                 if ( Pattern . matches ( "^[a-zA-Z]*$" , temp [ j ])){            

코딩 테스트 - MinAbsSum

import java . util . Arrays ; public class MinAbsSum_230121 {     public static void main ( String [] args ) {         int [] A = { 1 , 5 , 2 ,- 2 };         System . out . println ( solution ( A ));     }     /*             {−1, 1} 집합에서 N 정수의 배열 A와 N 정수의 시퀀스 S에 대해 다음과 같이 val(A, S)를 정의합니다.             값(A, S) = | 합계 { A[i]*S[i] for i = 0..N−1 }|             (0 요소의 합이 0이라고 가정합니다.)             주어진 배열 A에 대해 우리는 val(A,S)를 최소화하는 시퀀스 S를 찾고 있습니다.             N개의 정수 배열 A가 주어지면 세트 {−1, 1}에서 N 정수의 모든 가능한 시퀀스 S에 대해             val(A,S)의 모든 가능한 값에서 val(A,S)의 최소값을 계산합니다.             예를 들어 주어진 배열은 다음과 같습니다.             A[0] = 1             A[1] = 5             A[2] = 2             A[3] = -2             S = [−1, 1, −1, 1], val(A, S) = 0에 대해 가능한 최소값이므로 함수는 0을 반환해야 합니다.      */           public static int solution ( int [] A ) {         //정수 배열이 주어지면 요소의 최소 절대 합계를 찾는다             if ( A . length == 0 ){             return 0 ;         } else if ( A . length == 1 ){             return

코딩 테스트 - NumberSolitaire

class NumberSolitaire {     public static void main ( String [] args ) {         int [] A = { 1 ,- 2 , 0 , 9 ,- 1 ,- 2 };         System . out . println ( solution ( A ));     }     public static int solution ( int [] A ) {                 int [] arr = new int [ A . length ];         //조약돌은 정사각형 숫자 0에 표시되어 있습니다. 0 - 0         arr [ 0 ] = A [ 0 ];         for ( int i = 1 ; i < A . length ; i ++){                         int 최대가능한결과 = - 2147483648 ; //Integer.MIN_VALUE                         for ( int 주사위 = 1 ; 주사위 <= 6 ; 주사위 ++){                 if ( i - 주사위 >= 0 ){                     최대가능한결과 = Math . max ( arr [ i - 주사위 ]+ A [ i ], 최대가능한결과 );                     System . out . println ( i + "번째, 주사위값 : " + 주사위 + " 최대 가능한 결과 " + 최대가능한결과 );                 }             }                 arr [ i ] = 최대가능한결과 ;         }                 return arr [ A . length - 1 ];     }     /*         1인용 게임은 0에서 N-1까지 번호가 매겨진 N개의 연속된 사각형으로 구성된 보