Skip to content

Instantly share code, notes, and snippets.

View haruple97's full-sized avatar
๐Ÿ˜

Kim Dong Hwan haruple97

๐Ÿ˜
View GitHub Profile
@haruple97
haruple97 / Solution.java
Created November 24, 2021 03:40
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA] K๋ฒˆ์งธ์ˆ˜
import java.util.*;
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length]; //commands[i] ๋งŒํผ์˜ ๋ฐฐ์—ด ์ƒ์„ฑ
int[] temp = {}; //temp ๋ฐฐ์—ด ์ƒ์„ฑ
for(int i=0; i<commands.length; i++){
temp = Arrays.copyOfRange(array, commands[i][0]-1, commands[i][1]); //์ž๋ฅด๊ธฐ
Arrays.sort(temp); //์ •๋ ฌ
@haruple97
haruple97 / Solution.java
Last active October 29, 2021 15:44
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ๊ธฐ๋Šฅ๊ฐœ๋ฐœ (ํ)
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
Queue<Integer> queue = new LinkedList<>();
for(int i=0; i<progresses.length; i++){
queue.add((int) (Math.ceil((100.0 - progresses[i]) / speeds[i])));
}
List<Integer> answer = new ArrayList<>();
@haruple97
haruple97 / Solution.java
Created October 29, 2021 15:01
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ๊ธฐ๋Šฅ๊ฐœ๋ฐœ (๋ฐฐ์—ด ํ’€์ด)
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int[] temp = new int[100]; //์ž‘์—…์˜ ๊ฐœ์ˆ˜๋Š” 100๊ฐœ ์ดํ•˜์ด๋ฏ€๋กœ 100์œผ๋กœ ์„ ์–ธ
int day = 0; //temp์— ์ ์šฉํ•  ๋ฐฐํฌ์ผ ์ˆ˜
//๊ฐ ํ•ญ๋ชฉ๋งˆ๋‹ค 100๊นŒ์ง€ ๊ฒ€์‚ฌํ•ด์•ผํ•˜๋ฏ€๋กœ for๋ฌธ์•ˆ์— while๋ฌธ์ด ๋“ค์–ด๊ฐ„๋‹ค.
for(int i=0; i<progresses.length; i++){
while(progresses[i] + (speeds[i] * day) < 100){
day++;
}
@haruple97
haruple97 / Solution.java
Created October 29, 2021 12:00
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA H-Index
import java.util.*;
class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations); //๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
for(int i=0; i<citations.length; i++){
int h=citations.length-i;
@haruple97
haruple97 / Solution.java
Created October 29, 2021 04:32
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ์ œ์ผ ์ž‘์€ ์ˆ˜ ์ œ๊ฑฐํ•˜๊ธฐ
class Solution {
public int[] solution(int[] arr) {
//๋ฐฐ์—ด ๊ธธ์ด๊ฐ€ 1์ธ ๊ฒฝ์šฐ
if(arr.length == 1){
int[] answer = {-1};
return answer;
}
//๋ฐฐ์—ด๊ธธ์ด๊ฐ€ 1๋ณด๋‹ค ํด ๋•Œ
@haruple97
haruple97 / Solution.java
Created October 29, 2021 03:04
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ์ž๋ฆฟ์ˆ˜๋”ํ•˜๊ธฐ (์ •์ˆ˜ ๋‚˜๋ˆ—์…ˆ)
public class Solution {
public int solution(int n) {
int answer = 0;
while(n > 0){
answer += n%10;
n/=10;
}
return answer;
}
@haruple97
haruple97 / Solution.java
Created October 29, 2021 03:00
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ์ž๋ฆฟ์ˆ˜ ๋”ํ•˜๊ธฐ (String ๋ณ€ํ™˜ ๋ฐฉ๋ฒ•)
public class Solution {
public int solution(int n) {
int answer = 0;
String s = Integer.toString(n); //int n์„ String์œผ๋กœ ๋ณ€ํ™˜
for(int i=0; i<s.length(); i++){
answer += Integer.parseInt(s.substring(i, i+1));
}
return answer;
}
@haruple97
haruple97 / Solution.java
Created October 28, 2021 12:58
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ์ด์ƒํ•œ ๋ฌธ์ž ๋งŒ๋“ค๊ธฐ
class Solution {
public String solution(String s) {
String answer = "";
String[] str = s.split("");
int idx = 0; //์ธ๋ฑ์Šค
for(int i=0; i<str.length; i++){
if(str[i].equals(" ")){ //๋„์–ด์“ฐ๊ธฐ ์žˆ๋‹ค๋ฉด
idx = 0; //์ธ๋ฑ์Šค 0 ์ดˆ๊ธฐํ™”
}
@haruple97
haruple97 / Solution.java
Created October 28, 2021 12:24
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ์‹œ์ €์•”ํ˜ธ
class Solution {
public String solution(String s, int n) {
String answer = "";
for(int i=0; i<s.length(); i++){
char ch = s.charAt(i);
if(Character.isLowerCase(ch)){ //์†Œ๋ฌธ์ž
ch = (char)((ch-'a'+n)%26 + 'a');
}
@haruple97
haruple97 / Solution.java
Created October 28, 2021 06:33
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JAVA ๊ฐ€์šด๋ฐ ๊ธ€์ž ๊ฐ€์ ธ์˜ค๊ธฐ (charAt)
class Solution {
public String solution(String s) {
String answer = "";
if(s.length() % 2 == 0){ //์ง์ˆ˜
answer += s.charAt(s.length()/2-1);
answer += s.charAt(s.length()/2)
}
else { //ํ™€์ˆ˜
answer += s.charAt(s.length()/2);