전체보기 (113) 썸네일형 리스트형 N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space respectively. 어떻게 풀면 좋을까? 일단 퀸은 오와 열, 대각선 방향으로 칸 수에 상관없이 움직일 수 있.. Coin Change (DP) You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. 이 문제는 자신이 카페 알바생이라고 생각하며 풀어보자. 당신은 손님들에게 거스름돈을 어떻게 남겨줄것인가?손님들은 되도록이면 잔돈의 수가 적기를 바랄 것이다.아마 보통 알바생들은 가장 큰 단위의 돈부터 집어들고 점점 더 작은 단위로 내려가면서 돌.. 중복 있는 순열 문자열이 주어졌을 때 모든 경우의 순열을 계산하는 메서드를 작성하라. 문자는 중복되어 나타날 수 있지만, 나열된 순열은 서로 중복되면 안 된다. 이 문제에서는 중복된 순열을 어떻게 찾아낼 것인가에 대하여 생각해보아야 한다.단순히 모든 순열을 구한 후에 배열에 이 순열이 존재하지않으면 추가하는 방법으로 해결할 수 있다. 하지만 이 해결책은 최악의 경우 시간이 소요될 것이다. 그럼, 어떻게 접근해야할까? 먼저 작은 문제로 쪼개서 생각해보자.'abca'라는 문자열이 주어졌다. 이 문자열의 순열을 구하려면 어떻게 해야할까?중복 없는 순열을 풀때와 같이 문자열의 한 문자와 나머지 문자열의 순열을 구하고 이를 모두 합치면 된다.수식으로 표현해보자면 다음과 같다. 하지만, 중복이 있는 문자열의 경우라면 빨간색으로 표.. 중복 없는 순열 문자열이 주어졌을 때 모든 경우의 순열을 계산하는 메서드를 작성하라. 단, 문자는 중복되어 나타날 수 없다. 다른 문제들과 마찬가지로, 작은 문제에서부터 확장하는 방식으로 생각해보자. (1) 길이가 1인 문자열 (2) 길이가 2인 문자열 그렇다면 길이가 3인 문자열은 어떻게 만들 수 있을까? 배열의 모든 요소를 첫번째로 놓고 나머지 요소들의 순열을 덧붙이면된다.문제가 훨씬 쉬워졌다! 그림으로 표현하자면 다음과 같다. 그럼 이제 코드로 표현을 해보자.재귀 함수를 쓰면 아주 간단하게 표현할 수 있다. 123456789101112131415161718class Solution: def permute(self, nums: List[int]) -> List[List[int]]: def backtrack(start.. Topological Sorting (위상 정렬) Topological sorting for Directed Acyclic Graph(DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG. Topological Sorting vs Depth First Traversal (DFS) In DFS, we print a vertex and then recursively call DFS for its adjacent vertices. In topological sorting, w.. What is a Hoisting? Conceptually, a strict definition of hoisting suggests that variable and function declarations are physically moved to the top of your code, but this is not in fact what happens.Instead, the variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code. Example Technical exampleOne of the advantage of JavaScript putting functi.. What is a Closure? A closure is the combination of a function and the lexical environment within which that function was declared.-- MDN web docs - Then, what is the lexical environment? Lexical scoping 123456789101112131415161718function init(){ var name = "J.Cole"; /* printName has no local variables of its own. However, because inner functions have access to the variables of outer functions, printName() can acc.. What is a Promise? The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. 1234567891011121314var promise1 = new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo'); }, 300);}); promise1.then(function(value) { console.log(value); // expected output: "foo"}); console.log(promise1);// expected output: [object Promise] Colored by.. 이전 1 ··· 5 6 7 8 9 10 11 ··· 15 다음