剪枝的实现和特性
初级搜索
- 1,朴素搜索:暴力搜索;
- 2,优化方式:不重复(fibonacci)、剪枝(生成括号问题);
- 3,搜索方向:深度优先搜索、广度优先搜索、双向搜索、启发式搜索。
双向BFS的实现、特性
单向BFS
1,目标函数单调性(单调递增或者递减)——在有序的里面查找
2,存在上下界(bounded)
3,能够通过索引访问(index accessible)
(一定要写的非常熟练)
1 | left,right := 0,len(array) - 1 |
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
To determine how you “say” a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
1 | Example 1: |
Given an array nums and a value val, remove all instances of that value in-place and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
The order of elements can be changed. It doesn’t matter what you leave beyond the new length.