Notice
Recent Posts
Recent Comments
Link
목록2021/05/25 (2)
잡다한 IT 지식
문제출처 [처음 짠 코드] 처음 생각한 코드는 인덱스는 중복이 안 되고 문자와 세트이므로 map으로 넣은 후에 key를 정렬해서 받아오는 방법을 생각함. import java.util.HashMap; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; class Solution { public String restoreString(String s, int[] indices) { Map map = new HashMap(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < indices.length; i++) { map.put(indices[i], s.charAt(i))..
알고리즘 문제 풀이
2021. 5. 25. 23:37
숫자 각 자릿수에 곱과 합을 빼서 리턴해주는 문제. 10으로 나눈 나머지가 1의 자릿수의 값이 됨. 0이 될 때까지 계속 반복하면 모든 자릿수를 거쳐갈 수 있음. [내가 짠 코드] class Solution { public int subtractProductAndSum(int n) { int number = n; int multilSum = 1; int sum = 0; while (number > 0) { int temp = number % 10; sum += temp; multilSum *= temp; number /= 10; } return multilSum- sum; } }
알고리즘 문제 풀이
2021. 5. 25. 22:35