Skip to content

Commit 1dd82f7

Browse files
LetMeFly666Copilot
andauthored
update: 添加问题“2110.股票平滑下跌阶段的数目”的代码和题解 (#1226)
* 1problem1day: archive * 1problem1day: history function done * 2110: init(#1225) * 2110: AC.cpp+py + WA.go + CE.java (#1225) cpp - AC,100.00%,19.93% py - AC,100.00%,50.20% * 2110: AC.go+java+rust (#1225) go - AC,28.57%,46.43% java - AC,27.97%,30.07% rust - AC,14.29%,14.29% 上一个commitmsg写错了,不是CE.java应该是RE.java * update: 添加问题“2110.股票平滑下跌阶段的数目”的代码和题解 (#1226) Signed-off-by: LetMeFly666 <[email protected]> * fix: Update tryGoPy/ReLeetcode/processHistory.py Co-authored-by: Copilot <[email protected]> * 1problem1day: 历史题目(自2025.4.1)处理完毕 * 1problem1day: archive --------- Signed-off-by: LetMeFly666 <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 023153a commit 1dd82f7

17 files changed

+540
-156
lines changed

.commitmsg

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-15 13:32:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-15 18:52:23
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
typedef long long ll;
12+
class Solution {
13+
public:
14+
ll getDescentPeriods(vector<int>& prices) {
15+
ll ans = 0, cnt = 0;
16+
int last = 0;
17+
for (int t : prices) {
18+
if (t != last - 1) {
19+
ans += cnt * (cnt + 1) / 2;
20+
// printf("t = %d, cnt = %lld\n", t, cnt);
21+
cnt = 0;
22+
}
23+
last = t;
24+
cnt++;
25+
}
26+
return ans + cnt * (cnt + 1) / 2;
27+
}
28+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-15 13:32:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-15 21:46:22
6+
*/
7+
package main
8+
9+
func getDescentPeriods(prices []int) (ans int64) {
10+
var cnt int64
11+
last := 0
12+
for i := 0; i <= len(prices); i++ {
13+
if i == len(prices) || prices[i] != last - 1 {
14+
ans += cnt * (cnt + 1) / 2
15+
cnt = 0
16+
}
17+
cnt++
18+
if i < len(prices) {
19+
last = prices[i]
20+
}
21+
}
22+
return
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-15 13:32:17
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-15 21:37:22
6+
*/
7+
class Solution {
8+
public long getDescentPeriods(int[] prices) {
9+
long ans = 0, cnt = 0;
10+
for (int last = 0, i = 0; i <= prices.length; i++) {
11+
if (i == prices.length || prices[i] != last - 1) {
12+
ans += cnt * (cnt + 1) / 2;
13+
cnt = 0;
14+
}
15+
cnt++;
16+
if (i < prices.length) {
17+
last = prices[i];
18+
}
19+
}
20+
return ans;
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-12-15 13:32:17
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-15 18:54:39
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def getDescentPeriods(self, prices: List[int]) -> int:
11+
ans = last = cnt = 0
12+
for p in prices:
13+
if p != last - 1:
14+
ans += cnt * (cnt + 1) // 2
15+
cnt = 0
16+
cnt += 1
17+
last = p
18+
return ans + cnt * (cnt + 1) // 2
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-15 21:33:12
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-15 21:41:17
6+
*/
7+
impl Solution {
8+
pub fn get_descent_periods(prices: Vec<i32>) -> i64 {
9+
let mut ans: i64 = 0;
10+
let mut cnt: i64 = 0;
11+
let mut last: i32 = 0;
12+
for p in prices { // 一借不还
13+
if p != last - 1 {
14+
ans += cnt * (cnt + 1) / 2;
15+
cnt = 0;
16+
}
17+
cnt += 1;
18+
last = p;
19+
}
20+
ans + cnt * (cnt + 1) / 2
21+
}
22+
}

Codes/2147-number-of-ways-to-divide-a-long-corridor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Solution {
3737
}
3838
}
3939
}
40-
if (!ing && now != 0 || !atLeast2) {
40+
if (!ing || !atLeast2) {
4141
return 0;
4242
}
4343
return static_cast<int>(ans);

Codes/2147-number-of-ways-to-divide-a-long-corridor_Better.cpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

Codes/3606-coupon-code-validator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* @Author: LetMeFly
3-
* @Date: 2025-12-13 22:41:43
3+
* @Date: 2025-12-13 22:26:53
44
* @LastEditors: LetMeFly.xyz
55
* @LastEditTime: 2025-12-13 22:42:29
66
*/

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-11-01 22:18:35
66
*/
77
pub struct Solution;
8-
include!("3531-count-covered-buildings.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("2110-number-of-smooth-descent-periods-of-a-stock.rs"); // 这个fileName是会被脚本替换掉的

0 commit comments

Comments
 (0)