재귀함수

    [LeetCode] 326. Power of Three

    326. Power of Three Easy Given an integer n, return true if it is a power of three. Otherwise, return false. An integer n is a power of three, if there exists an integer x such that n == 3x. Example 1: Input: n = 27 Output: true Explanation: 27 = 33 Example 2: Input: n = 0 Output: false Explanation: There is no x where 3x = 0. Example 3: Input: n = -1 Output: false Explanation: There is no x whe..

    [LeetCode] 323. Number of Connected Components in an Undirected Graph

    [LeetCode] 323. Number of Connected Components in an Undirected Graph

    323. Number of Connected Components in an Undirected Graph Medium You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph. Return the number of connected components in the graph. Example 1: Input: n = 5, edges = [[0,1],[1,2],[3,4]] Output: 2 Example 2: Input: n = 5, edges = [[0,1],[1,2],[2..

    [LeetCode] 22. Generate Parentheses

    [LeetCode] 22. Generate Parentheses

    22. Generate Parentheses Medium Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] Constraints: 1 cnt2: dfs(cnt1, cnt2 + 1, temp + ')') dfs(0, 0, '') return res