Devops/Algorithm

·Devops/Algorithm
10진수로 변환 시, 'A' (10) 보다 클 경우, 'A'만큼 빼주고 대신 10을 더해준다. 'A' (10) 보다 작을 경우, '0'을 빼주면서 int로 변환 3진수로 변환 시, StringBuilder의 insert를 통해 맨 앞 index=0에 계산된 값을 추가한다. import java.util.*; class Solution { public int solution(int n) { String Third = toThird(n); String Third_reverse = Change_Seq(Third); int answer = toTen(Third_reverse); return answer; } public static String toThird(int n){ StringBuilder sb = ne..
·Devops/Algorithm
정수 제곱근 판별 2가지 방법 Math.sqrt() vs Math.pow() Math.sqrt import java.util.*; class Solution { public long solution(long n) { if(Math.sqrt(n)==(int)Math.sqrt(n)) return (long)Math.pow(Math.sqrt(n)+1,2); return -1; } } Math.pow ( 출력시 Type 변환 필요 ) import java.util.*; class Solution { public long solution(long n) { for(int i = 0;i*i
·Devops/Algorithm
HashSet 중복된 값(원소)는 추가되지 않는 특성을 가짐 package practice; import java.util.*; public class hashset { public static void main(String[] args) { /////////////////////////////////////////////// System.out.print("1. 추가 : "); Set hashSet = new HashSet(); hashSet.add("APPLE"); hashSet.add("BANANA"); hashSet.add("ORANGE"); Iterator it = hashSet.iterator(); while(it.hasNext()) System.out.print(it.next()+" "); ..
·Devops/Algorithm
Combination A: 4, B: 3, C;5 를 조합할때, 1~3개의 조합 경우의수 구하기 ★★★ (A+1)*(B+1)*(C+1) = ABC + AB + BC + CA + A + B + C + 1 ※ 모두 고르지 않는 경우인 상수는 제외. Solution : ( 4 + 1 ) * ( 3 + 1 ) * ( 5 + 1 ) -1 import java.util.*; class Solution { static int answer = 1; public int solution(String[][] clothes) { HashMap hm = new HashMap(); for(int i=0;i
·Devops/Algorithm
소수 구하기 11을 소수판별 하기 위해서는 2에서 11의 제곱근까지만 확인해보면 된다. ★ 49와 같이 n^2 의 경우 제곱근 7까지 탐색 for ( int i=2; i*i
·Devops/Algorithm
substring(int start, int end) - String 자르기 charAt(int index) import java.util.Stack; public class Solution { public static void main(String[] args) { String word = "ABCDEFG"; String sub_word; // substring() sub_word = word.substring(3); // "DEFG" sub_word = word.substring(1,word.length()); // "BCDEFG" sub_word = word.substring(0,word.length()-1); // "ABCDEF" // charAt() char A = word.charAt(0); ..
Cold Water Project
'Devops/Algorithm' 카테고리의 글 목록