순열 N : 자연수 R : 뽑을 갯수 nPr 구하기! 자연수 import org.junit.jupiter.api.Test import java.util.* class Permutation { private var N: Int = 0 private var R: Int = 0 private fun dfs(curNum: Int, visited: BooleanArray, depth: Int, strBuilder: StringBuilder, answerList: LinkedList) { strBuilder.append(curNum) if (depth == R) { answerList.add(strBuilder.toString().toInt()) strBuilder.setLength(strBuilder.length..
Algorithm
김성렬 교수님의 알고리즘 수업 리뷰 + 알고리즘 문제풀이🔒 Problem 🔑 BFS approach Create two queue with bread-first search to all nodes. To handle null case, if null, don't add left & right nodes to queue BFS Code (Kotlin) import java.util.LinkedList import java.util.Queue class TreeNode(var `val`: Int) { var left: TreeNode? = null var right: TreeNode? = null } class SameTree { fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean { // 1. queue 2개 초기화 및..
When to use Find targetValue in sorted array Algorithm Recursive approach 1. StartIndex = 0 (lower bound), endIndex = arr.length (upper bound), midIndex = starIndex + endIndex / 2, 2. Recursion until (startIndex > endIndex (Not found)) . arr[midIndex] == targetValue ? => return midIndex .arr[midIndex] > targetValue ? => endIndex = mid – 1 (targetValue on left side) .arr[midIndex] < targetValue ?..