Week Training: 413 Arithmetic Slices
来源:互联网 发布:删除不了windows.old 编辑:程序博客网 时间:2024/06/10 17:53
Many ways to do, using dp, we can let dp[i] be the number of slices until i in the array, so the state transformation is dp[i]=dp[i-1]+1, when the new number is able to make a arithmetic slice with before. The total number is to add numbers of each position until the last element.
class Solution {public: int numberOfArithmeticSlices(vector<int>& A) { int l = A.size(); vector<int> dp(l); int num = 0; for(int i=0;i<l;i++){ dp[i]=0; } for(int i=2;i<l;i++){ if(A[i-1]-A[i-2]==A[i]-A[i-1]){ dp[i] = dp[i-1]+1; } num += dp[i]; } return num; }};
阅读全文
0 0
- Week Training: 413 Arithmetic Slices
- [leetcode 413. Arithmetic Slices]medium|week 12
- LeetCode #413: Arithmetic Slices
- LeetCode【413】Arithmetic Slices
- leetcode 413 Arithmetic Slices
- LeetCode #413 - Arithmetic Slices - Medium
- leetcode 413 Arithmetic Slices C++
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- Arithmetic Slices
- LeetCode 413 Arithmetic Slices (找等差数列)
- Leetcode 413 - Arithmetic Slices(dp)
- 413. Arithmetic Slices
- 解决ubuntu无法修改分辨率为1920*1080问题
- MySQL日期和时间类型
- Day3
- linux 下C操作SQLite(增删改查)
- Python3 配置文件(configparser)
- Week Training: 413 Arithmetic Slices
- C++递归算法之放苹果
- 全面解析Android之Handler机制
- POJ-3176 Cow Bowling
- java反射机制
- JZOJ1517.2017.05.27【提高组】模拟赛C组 T1背包问题
- 存储类,作用域,生命周期和链接属性
- Linux命令---- mv移动或重命名文件/目录
- CentOS 7 搭建ngrok服务器,从此不再需要花生壳