fix: 修复空提交问题

This commit is contained in:
1
2025-11-23 23:38:03 +00:00
parent aa4574b5eb
commit 240c349b8a
45 changed files with 113 additions and 4438 deletions

View File

@@ -8,3 +8,12 @@ func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool
}
return -1, nil, false
}
func LastFourElements[T any](s []T, n1 int) []T {
n := len(s)
if n <= n1 {
// 切片长度小于等于4时返回整个切片
return s
}
// 切片长度大于4时返回最后4个元素从n-4索引到末尾
return s[n-n1:]
}