ARST打卡第121周[121/521]

Algorithm

lc1588_所有奇数长度子数组的和

思路

感觉就是记录(各点 i 距离中心的的距离 + 1) / 2 * a[i]的和

对于偶数还是不太成熟…只对于奇数比较有用,这个规律也没有验证,推荐还是看题解的左右奇数个包含自己的个数值

https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays/solution/suo-you-qi-shu-chang-du-zi-shu-zu-de-he-yoaqu/

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int sumOddLengthSubarrays(vector<int>& arr) {
int sum = 0;
int n = arr.size();
for (int i = 0; i < n; i++) {
int leftCount = i, rightCount = n - i - 1;
int leftOdd = (leftCount + 1) / 2;
int rightOdd = (rightCount + 1) / 2;
int leftEven = leftCount / 2 + 1;
int rightEven = rightCount / 2 + 1;
sum += arr[i] * (leftOdd * rightOdd + leftEven * rightEven);
}
return sum;
}
};

Review

https://docs.ceph.com/en/latest/radosgw/adminops/#get-usage

Tips

POST跟GET请求的区别

Share

git加签名

1
git cm -s -m "signed-by test by add '-s'"

markdown展示diff效果, 在代码块后面加上 diff

1
2
- a
+ b