AVL树
- 发明者:Adelson-Velsky and Landis Tree
- Blance Factor(平衡因子):是它的左子树的高度减去它的右子树的高度(有时相反)。balance factor= {-1,0,1}
- 通过旋转操作来进行平衡(四种)
- Self-balancing binary search tree
- 不足:结点需要存储额外信息、且调整次数频繁
记录左右子树高度
例如F点,右子树高度1 - 左子树高度2 = -1
例如F点,右子树高度1 - 左子树高度2 = -1
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.