본질을 이해하지 못하면 되는 일이 없다.
너의 모든 에너지를 너의 것이 아닌 회사에 몰빵 하지 말라.
개발자는 별 거 아닌 (것처럼 보이는) 코드를 못 짤 때 가장 아프고 슬프다.
private boolean isPrime(int number) {
if (number == 2) return true;
if (number < 2 || number % 2 == 0) return false;
for (int i = 3; i <= Math.sqrt(number); i += 2) {
if (number % i == 0) {
return false;
}
}
return true;
}
class NumberCombinationSolution {
public int solution(int[] cards) {
SortedSet<String> set = new TreeSet<>();
boolean[] checked = new boolean[cards.length];
for (int length = 1; length <= cards.length; length++) {
dfs(cards, set, "", checked, length);
}
return set.size();
}
private void dfs(int[] cards, SortedSet<String> set, String current, boolean[] checked, int length) {
if (current.length() == length) {
set.add(current);
return;
}
for (int i = 0; i < cards.length; i++) {
if (!checked[i]) {
checked[i] = true;
dfs(cards, set, current + cards[i], checked, length);
checked[i] = false;
}
}
}
private boolean isPrime(int number) {
if (number == 2) return true;
if (number < 2 || number % 2 == 0) return false;
for (int i = 3; i <= Math.sqrt(number); i += 2) {
if (number % i == 0) {
return false;
}
}
return true;
}
}
if (current.length() == length) {
set.add(current);
return;
}
dfs(cards, set, current + cards[i], checked, length);
public int solution(int number) {
// return IntStream.rangeClosed(1, number).sum(); // 이건 재귀 함수가 아니다, jdk8+ 이용자여!
return sum(number);
}
int sum(int number) {
if (number == 1) {
return 1;
}
return ?
}
int sum(int number) {
if (number == 1) {
return 1;
}
return number + sum(number - 1);
}
public String solution(int decimal) {
return convert(decimal);
}
String convert(int decimal) {
if (decimal < 2) {
return String.valueOf(decimal);
}
return ?;
}
String convert(int decimal) {
if (decimal < 2) {
return String.valueOf(decimal);
}
return convert(decimal / 2) + decimal % 2;
}
public void solution(int[] cards) {
Set<String> numbers = new HashSet<>();
print(cards, set);
numbers.forEach(System.out::println);
}
private void print(int[] cards, Set<String> numbers) {
return;
}
int[] cards = {1};
int[] cards = {1, 2};
public void solution(int[] cards) {
Set<String> numbers = new HashSet<>();
for (int length = 1; length <= cards.length; length++) {
print(cards, numbers, length);
}
numbers.forEach(System.out::println);
}
private void print(int[] cards, Set<String> numbers, int length) {
return;
}
public void solution(int[] cards) {
Set<String> numbers = new HashSet<>();
for (int length = 1; length <= cards.length; length++) {
print(cards, numbers, "", length);
}
numbers.forEach(System.out::println);
}
private void print(int[] cards, Set<String> numbers, String current, int length) {
return;
}
private void print(int[] cards, Set<String> numbers, String current, int length) {
if (current.length() == length) {
numbers.add(current);
return;
}
return;
}
private void print(int[] cards, Set<String> numbers, String current, int length) {
if (current.length() == length) {
numbers.add(current);
return;
}
for (int i = 0; i < cards.length; i++) {
print(cards, numbers, current + cards[i], length);
}
}
11
22
1
12
2
21
public void solution(int[] cards) {
Set<String> numbers = new HashSet<>();
boolean[] visited = new boolean[cards.length];
for (int length = 1; length <= cards.length; length++) {
print(cards, numbers, "", visited, length);
}
numbers.forEach(System.out::println);
}
private void print(int[] cards, Set<String> numbers, String current, boolean[] visited, int length) {
if (current.length() == length) {
numbers.add(current);
return;
}
for (int i = 0; i < cards.length; i++) {
print(cards, numbers, current + cards[i], visited, length);
}
}
private void print(int[] cards, Set<String> numbers, String current, boolean[] visited, int length) {
if (current.length() == length) {
numbers.add(current);
return;
}
for (int i = 0; i < cards.length; i++) {
if (!visited[i]) {
visited[i] = true;
print(cards, numbers, current + cards[i], visited, length);
visited[i] = false;
}
}
}
1
12
2
21