Array

常用算法:two pointer, binary search(二分法), DP, hash, greedy, bit manipulation

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.

The greedy algorithms are sometimes also used to get an approximation for Hard optimization problems.

贪心算法与动态规划的不同在于它每对每个子问题的解决方案都做出选择,不能回退。动态规划则会保存以前的运算结果,并根据以前的结果对当前进行选择,有回退功能。


循环数组解法:

  1. 切断,化环为链
  2. 复制扩成两倍
  3. 取反元素反向思考(求max则求其余的min)

results matching ""

    No results matching ""