Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
393 posts
14 categories
117 tags

LeetCode 467. Unique Substrings in Wraparound String

Posted on 2022-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
int findSubstringInWraproundString(string p) {
int f[26] = {0}, cnt = 0;
for (int i = 0; i < p.size(); ++i) {
cnt = i && (p[i] - p[i - 1] + 26) % 26 == 1 ? cnt + 1 : 1;
f[p[i] - 'a'] = max(f[p[i] - 'a'], cnt);
}
return accumulate(f, f + 26, 0);
}
};
# Dynamic Programming# String
LeetCode 795. Number of Subarrays with Bounded Maximum
LeetCode 904. Fruit Into Baskets
© 2026 Shawn
Powered by Hexo & NexT.Mist
0%