leetcode 413 Arithmetic Slices C++
来源:互联网 发布:亚马逊买什么划算 知乎 编辑:程序博客网 时间:2024/05/16 01:31
最简单的解法就是3个一组,4个一组这样暴力的去遍历,效率低下。
所以通过找规律发现,等差数列每增加一个,总数增加的个数也是一个等差数列。
int numberOfArithmeticSlices(vector<int>& A) { if (A.size()<3) return 0; int count = 0; int phase = 0; for(int i = 0;i<A.size() - 2;i++) { if (A[i+1] - A[i] == A[i+2] - A[i+1]){ count += ++phase; } else { phase = 0; } } return count; }
所以这种题可以自己先拿笔找找规律。
0 0
- LeetCode #413: Arithmetic Slices
- LeetCode【413】Arithmetic Slices
- leetcode 413 Arithmetic Slices
- LeetCode #413 - Arithmetic Slices - Medium
- leetcode 413 Arithmetic Slices C++
- LeetCode 413. Arithmetic Slices 题解(C++)
- LeetCode 413 Arithmetic Slices (找等差数列)
- Leetcode 413 - Arithmetic Slices(dp)
- [LeetCode]413.Arithmetic Slices
- LeetCode: Arithmetic Slices
- Leetcode 413. Arithmetic Slices
- Leetcode-413. Arithmetic Slices
- 【LeetCode】413. Arithmetic Slices
- Leetcode-413. Arithmetic Slices
- LeetCode 413. Arithmetic Slices
- Leetcode 413. Arithmetic Slices
- LeetCode 413. Arithmetic Slices
- [LeetCode]413. Arithmetic Slices
- 监控系统故障定位之事件关联分析的设计
- firstChild和firstElementChild
- 通过UIActivityViewController分享内容
- org.apache.tomcat.util.bcel.classfile.ClassFormatException
- Java中Runnable和Thread的区别
- leetcode 413 Arithmetic Slices C++
- Wine 系统加载
- 磁盘剩余空间填0工具 - python
- 【leetcode】73. Set Matrix Zeroes【java】
- Spring Data JPA
- Mariadb----数据类型(三)
- Kendo ui Grid的创建步骤
- 如果存在表则删除表然后创建Mysql
- 一个足以让私有云服务彻底崩溃的“小坑”-聊聊CMDB的资产审计