일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- java 백준 1509
- 자바 1676
- java 1238
- javav 1676
- go
- java 파티
- kotiln const val
- 전략 패턴이란
- 백준 2252 줄세우기
- rabbitmq 싱글톤
- 익명 객체 @transactional
- spring mongodb switch
- java 팩토리얼 개수
- 백준 특정한 최단 경로
- Java Call By Refernce
- nodejs rabbitmq
- spring mongodb
- Spring ipfs
- ipfs singletone
- 백준 연결요소 자바
- kotiln const
- java 1509
- spring mongoTemplate
- spring mongoTemplate switch
- 백준 1504 java
- kotiln functional interface
- 안정해시
- ipfs bean
- mongodb lookup
- 자바 백준 팩토리얼 개수
- Today
- Total
목록코테 (79)
공부 흔적남기기
class Solution { public int solution(int x) { //이 문제는 풀기전에 10진수를 다른 진법으로 어떻게 바꾸는지 알고 풀면 편함 String ans = ""; // 10진수 -> 3진수로 변환하는 과정 //간단히 설명하면 ... 81, 27, 9, 3, 1 이렇게 위에서 부터 나타내는데 // 나누어 떨어진다면 0값 // 그렇지 않다면 나머지 값을 사용하면됨 // 반복문마다 x를 3으로 나눠줌 while(x>0){ ans = (x%3) +ans; x /=3; } // sb를 통해 리버스 시켜준후 StringBuffer sb =new StringBuffer(ans); String reverse = sb.reverse().toString(); int answer = 0; //..
class Solution { public boolean solution(int x) { //x를 string형태로 바꿔 한자리수 씩 확인 String s = String.valueOf(x); int sum =0; //모든 자리수를 더한다음에 for(int i =0; i
class Solution { public int solution(int num) { int count = 0; long tmp = num; /* 간단함 그냥 여기에 맞춰서 코딩하면됨 1-1. 입력된 수가 짝수라면 2로 나눕니다. 1-2. 입력된 수가 홀수라면 3을 곱하고 1을 더합니다. 2. 결과로 나온 수에 같은 작업을 1이 될 때까지 반복합니다. */ while (tmp != 1) { //count가 0부터 시작했으므로 500이 되는 순간 -1을 리턴해주기 if (count == 500) { return -1; } if (tmp % 2 == 0) { tmp /= 2; } else { tmp *= 3; tmp++; } count++; } return count; } } 출처: https://progr..
import java.util.ArrayList; import java.util.Collections; class Solution { public int[] solution(int[] arr) { ArrayList arrayList = new ArrayList(); int[] answer; //collection.min을통해 가장 작은수를 찾기위해 arrayList로 변환 for (int integer : arr) { arrayList.add(integer); } int min = Collections.min(arrayList); //배열의 길이가 1이면 삭제후 0 이되므로 {-1} 리턴 if(arr.length ==1){ answer = new int[]{-1}; }else{ answer = new i..
class Solution { public long solution(long n) { double tmp = Math.sqrt(n); //n을 루트를 붙여서 tmp에 저장 String s = String.valueOf(tmp); //string로 바꾼후 뒤에 .을 기준으로 나눔 String[] strings = s.split("\\."); //ex) 16 -> 4.0으로나옴 //ex) 3 -> 1.7xxx //.이 2개 이상이면 제곱근이 아님 if(strings[1].length() >2){ return -1; }else{// 제곱근이라면 +1 한다음 제곱해서 리턴 long answer = (long) (tmp+1); return answer*answer; } } } 출처: https://programm..
import java.util.Arrays; import java.util.Collections; class Solution { public long solution(long n) { long answer = n; String s = String.valueOf(answer); //n으로 받은 수롤 string으로 변환한후 String[] strings = s.split(""); //내림차순으로 바꾸기위해 배열로 바꿈 //지금 생각해보니 왜 StringBuilder에 있는 reverse를 사용안했지? //지금 생각들었으니 됐다. Arrays.sort(strings, Collections.reverseOrder()); //내림차순 배열로 바꾸고 String s2 = ""; //새로운 string에 하나씩 차..
class Solution { public int[] solution(long n) { String s = String.valueOf(n); //먼저 받은 수를 string으로 바꾼후 //저장할 배열을 할당함 int[] answer = new int[s.length()]; //string을 뒤부터 돌면서 배열에 저장하도록함 for(int i =s.length()-1; i > -1; i--){ answer[s.length()-1-i]= Integer.parseInt(String.valueOf(s.charAt(i))); } return answer; } } 출처: https://programmers.co.kr/learn/courses/30/lessons/12932 코딩테스트 연습 - 자연수 뒤집어 배열로 만..
public class Solution { public int solution(int n) { String s = String.valueOf(n); int sum = 0; // 수학식으로 숫자를 자릿수 별 바꾸는 방법도 있지만 번거롭기 떄문에 //string로 바꿔서 하나씩 뜯어서 더한다음에 //int 형으로 다시 바꿔서 return for(int i =0; i
class Solution { public String solution(String s) { String answer = ""; //문자열을 공백기준으로 나눔 //-1을 붙인 이유? -> zerolength를 모두 포함시킴 String[] strings = s.split(" ", -1); for(String str : strings){ //새로운 string을 만들어서 str을 바꿔줄 것임 String sum = ""; for(int i = 0; i
import java.util.HashMap; import java.util.Set; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; //HashMap를 사용하면 간단히 풀리는 문제 //key와 value 형태로 값을 저장함 -> key가 중복될 경우 자동으로 replace되니 조심 //EX{"name1" : 2, "name2", 1"} pytho의 dictionary 형태인데 저장하는 방식이 다를뿐임 HashMap hashMap = new HashMap(); //이름과 숫자로 해시맵을 하나 만듦 //이름이 겹칠 수 있는데 겹친다면 벨류값을 +1해줌 for (int ..