蓝桥杯JAVA--002
文章目录
- 1.需求
- 2.方法1
- 3.方法2--动态规划
1.需求
2.方法1
3.方法2–动态规划
class Solution {public int findIntegers(int n) {int[] dp = new int[31];dp[0] = dp[1] = 1;for (int i = 2; i < 31; ++i) {dp[i] = dp[i - 1] + dp[i - 2];}int pre = 0, res = 0;for (int i = 29; i >= 0; --i) {int val = 1 << i;if ((n & val) != 0) {res += dp[i + 1];if (pre == 1) {break;}pre = 1;} else {pre = 0;}if (i == 0) {++res;}}return res;}
}
知识点:动态规划,完全二叉树,满二叉树