[leetcode 78] Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set). 가능한 모든 부분집합을 구하라. Note: The solution set must not contain duplicate subsets. Example: Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 풀이: 전형적인 백트래킹 문제이다. cnt가 nums길이와 같아지면 종료하지만 그 전에 만들어지는 모든 경우의 수 역시 정답에 저장한다. class Solution { public: vector result; void BackTracking(int cnt, i..
2020. 10. 24.
[leetcode 200] Number of Islands
Given an m x n 2d grid map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water. Example 1: Input: grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ] Output: 1 Exa..
2020. 10. 23.