목록프로그래머스 (93)
csct3434
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public long[] solution(long[] numbers) { long[] answer = new long[numbers.length]; int index = 0; for (long number : numbers) { if (number % 2 == 0) { answer[index++] = number + 1; continue; } String binaryString = Long.toBinaryString(number); int idx = binaryStri..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int[] solution(int rows, int columns, int[][] queries) { int[] answer = new int[queries.length]; int[][] arr = new int[rows][columns]; int count = 0; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { arr[i][j] = ++count; } } count = 0; fo..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.HashMap; import java.util.Stack; class Solution { private final HashMap map = new HashMap(); public int solution(String s) { int answer = 0; map.put('(', 1); map.put('{', 2); map.put('[', 3); map.put(')', -1); map.put('}', -2); map.put(']', -3); StringBuilder stri..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; class Solution { public String[] solution(String[] orders, int[] course) { HashMap combinations = new HashMap(); for (St..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int[] solution(String s) { int rep = 0; int count = 0; while (!s.equals("1")) { rep++; String sWithoutZero = s.replace("0", ""); count += s.length() - sWithoutZero.length(); s = Integer.toBinaryString(sWithoutZero.length()); } return new int[]{rep, count}; ..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { private int[] count = new int[2]; public int[] solution(int[][] arr) { solve(arr, 0, 0, arr.length); return count; } private void solve(int[][] arr, int x, int y, int size) { if (isCompressible(arr, x, y, size)) { count[arr[x][y]]++; return; } size /= 2; solve(arr..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int[] solution(int n) { int total = n * (1 + n) / 2; int[][] array = new int[n][n]; int[] answer = new int[n * (1 + n) / 2]; int row = -1, col = 0, count = 0; while (count < total) { while (row + 1 < n && array[row + 1][col] == 0) { array[++row][col] = ++co..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.LinkedList; import java.util.Stack; class Solution { public long solution(String expression) { long answer = 0; expression = expression.replace("+", " + "); expression = expression.replace("-", " - "); expression = expression.replace("*", " * "); String[] prioriti..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; class Solution { public int[] solution(String s) { int[] answer; int count = 0; String[] subsets = s.replaceAll("},", "} ").substring(1, s.length() - 1).split(" "); Arrays.sort(subsets, Comparator.comp..
문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.Stack; class Solution { public String solution(String p) { // Phase 1 if (p.isEmpty()) { return p; } // Phase 2 int idx = 0, count = 0; while (idx < p.length()) { count += (p.charAt(idx++) == '(') ? 1 : -1; if (count == 0) { break; } } String u = p.substring(0, id..