LeetCode 解题报告 (51)-- 回溯法解决 N 皇后问题
原题如下: >The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
原题如下: >The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
Java 可分为两大数据类型:
原题如下: You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
Follow up: Could you do this in-place?
原题如下:
Given a collection of distinct numbers, return all possible permutations.
原题如下 >Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
原题如下:
Given an unsorted integer array, find the first missing positive integer.
LeetCode 解题报告 (39,40)-- 数字集合中找特定和
这两道题目 39. Combination Sum和 40. Combination Sum II均要求从给定的一个数字集合中找出若干个数字的和等于某个给定的数。解决方法有两种,第一种是回溯法,第二种是动态规划。下面分别讲述。
LeetCode 解题报告 (37)-- 回溯法解决数独问题
原题如下: >Write a program to solve a Sudoku puzzle by filling the empty cells.
Empty cells are indicated by the character '.'.
LeetCode 解题报告 (33,81,153,154)-- 二分搜索找旋转数组特定值
本文主要讲述如何在一个
Rotated Sorted Array
中找到特定的值,Rotated Sorted Array
指旋转了的数组,如4 5 6 7 0 1 2
就是0 1 2 4 5 6 7
的一个旋转数组。正常情况下遍历一遍即可,但是这样的时间复杂度为 \(O(n)\), 但是本文主要讲述通过二分查找将时间复杂度降到 \(O(log_2n)\)。LeetCode 解题报告 (32)-- 最长合法的子括号串
原题如下:
>Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
0%