PROGRAMMERS
-
[프로그래머스] [JAVA] [Level 2] [스택/큐] 올바른 괄호PROGRAMMERS/스택&큐 2022. 9. 14. 03:13
import java.util.*; class Solution { boolean solution(String s) { boolean answer = false; // s가 홀수이거나 첫문자가 ')' 이거나 마지막 문자가 '(' 일 때 그대로 return // 이 코드는 없어도 무관 if(s.length()%2!=0 || s.charAt(0)==')' || s.charAt(s.length()-1)=='('){ return answer; } Stack stk = new Stack(); for(int i=0; i LAST IN FIRST OUT , 나중에 들어간 것이 먼저 나옴 import java.util.Stack -> import Stack stack = new Stack() -> int형 스택 선언 s..
-
[프로그래머스] [JAVA] [Level 2] [연습문제] 최솟값 만들기PROGRAMMERS/연습문제 2022. 9. 9. 16:03
import java.util.*; class Solution { public int solution(int []A, int []B) { int answer = 0; int length = A.length; // 오름차순 정렬 Arrays.sort(A); Arrays.sort(B); // 누적 최솟값을 만들기 위해서는 (A의 가장 작은수)*(B의 가장 큰수)를 해야하기 때문에 for(int i=0; i
-
[프로그래머스] [JAVA] [Level 2] [연습문제] 이진 변환 반복하기PROGRAMMERS/연습문제 2022. 9. 9. 15:52
import java.util.*; class Solution { public int[] solution(String s) { int zeroCount=0; // 0의 개수를 세어 줄 카운트 int count=0; // 몇 회차 인지 세어 줄 카운트 int lengt = 0; // s의 길이 while(true){ // 문자열에서 0 카운트해주기 for(int i=0; i 10진법 Integer.toBinaryString(number) // 10진법 -> 2진법 Integer.toOctalString(number) // 10진법 -> 8진법 Integer.toHexString(number) // 10진법 ->16진법
-
[프로그래머스] [JAVA] [Level 2] [연습문제] JadenCase 문자열 만들기PROGRAMMERS/연습문제 2022. 9. 9. 02:03
1. 문자열에 더해주기 import java.util.*; class Solution { public String solution(String s) { String answer = ""; // 모든 단어를 소문자로 바꾸고 한 문자씩 짤라서 배열로 초기화시켜주기 String arr[] = s.toLowerCase().split(""); answer += Character.toUpperCase(s.charAt(0)); for(int i=1; i
-
[프로그래머스] [JAVA] [Level 2] [연습문제] 최댓값과 최솟값PROGRAMMERS/연습문제 2022. 9. 8. 02:10
import java.util.*; class Solution { public String solution(String s) { // 공백을 기준으로 배열로 만들어줌 String arr[] = s.split(" "); // 최댓값을 넣어줄 공간 초기화 int maxNum = Integer.MIN_VALUE; // 최솟값을 넣어줄 공간 초기화 int minNum = Integer.MAX_VALUE; // 값들을 저장할 변수 int num = 0; for(int i=0; imaxNum) { maxNum = num; } if (num
-
PROGRAMMERES Level 2 연습문제 124 나라의 숫자 (JAVA 자바)PROGRAMMERS/연습문제 2022. 9. 6. 17:58
class Solution { public String solution(int n) { String answer = ""; // 124진법으로 n%3을 했을 때 0은 4, 1은 1, 2는 2 String arr[] = {"4", "1", "2"}; while(n>0){ // 나머지 // 3번씩 반복되기 때문에 int a = n%3; n /= 3; // 3의 배수일 경우 자릿수가 하나 올라가기 때문에 if (a==0) n--; answer = arr[a] + answer; } return answer; } }