中文


[leetcode] Subsets

Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] 深搜DFS。 […]


[leetcode] Sudoku Solver

Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character ‘.’. You may assume that there will be only one unique solution. A sudoku puzzle… …and its solution numbers marked in red. 深搜加回溯剪枝。 class Solution { public: void […]


[leetcode] First Missing Positive

First Missing Positive Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant space. 关键是只允许常数空间。这里要突破思维定势,要改变给定数组的结构。 对于A[i],如果A[i] > 0 && A[i] <= n,则将它与A[i] – 1 位置的元素互换位置。 遍历一遍后,再从左到右找到第一个A[i] != i + […]