DFS

    [LeetCode] 834. Sum of Distances in Tree

    [LeetCode] 834. Sum of Distances in Tree

    834. Sum of Distances in Tree Hard There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. Return an array answer of length n where answer[i] is the sum of the distances between the ith node in the tree and all other no..

    [LeetCode] 886. Possible Bipartition

    886. Possible Bipartition Medium We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group. Given the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split every..

    [LeetCode] 1971. Find if Path Exists in Graph

    [LeetCode] 1971. Find if Path Exists in Graph

    1971. Find if Path Exists in Graph Easy There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself. ..

    [LeetCode] 1066. Campus Bikes II

    [LeetCode] 1066. Campus Bikes II

    1066. Campus Bikes II Medium On a campus represented as a 2D grid, there are n workers and m bikes, with n

    [LeetCode] 841. Keys and Rooms

    841. Keys and Rooms Medium There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the o..

    [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] 139. Word Break

    139. Word Break Medium Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multiple times in the segmentation. Example 1: Input: s = "leetcode", wordDict = ["leet","code"] Output: true Explanation: Return true because "leetcode" can be segm..

    [LeetCode] 131. Palindrome Partitioning

    131. Palindrome Partitioning Medium Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example 1: Input: s = "aab" Output: [["a","a","b"],["aa","b"]] Example 2: Input: s = "a" Output: [["a"]] Constraints: 1 = len(s): self.ans.append(temp.copy()) for i in range(idx, len(s)): if palin(s, idx, i): temp.append(s..