[LeetCode]467. Unique Substrings in Wraparound String
来源:互联网 发布:浙江卫视网络直播源 编辑:程序博客网 时间:2024/05/17 01:26
https://leetcode.com/problems/unique-substrings-in-wraparound-string/
int[26]记录以每个字符为结尾的最大子字符串长度,最后求和该数组即为所求
public class Solution { public int findSubstringInWraproundString(String s) { if (s == null || s.length() == 0) { return 0; } int[] cache = new int[26]; int count = 1; int res = 0; cache[s.charAt(0) - 'a'] = 1; for (int i = 0; i < s.length() - 1; i++) { if (s.charAt(i + 1) - s.charAt(i) == 1 || (s.charAt(i) - s.charAt(i + 1) == 25 && s.charAt(i) == 'z')) { count++; } else { count = 1; } cache[s.charAt(i + 1) - 'a'] = Math.max(cache[s.charAt(i + 1) - 'a'], count); } for (int num : cache) { res += num; } return res; }}
0 0
- Leetcode-467. Unique Substrings in Wraparound String
- Leetcode 467. Unique Substrings in Wraparound String
- 【LeetCode】467. Unique Substrings in Wraparound String
- Leetcode-467. Unique Substrings in Wraparound String
- [LeetCode]467. Unique Substrings in Wraparound String
- **LeetCode 467. Unique Substrings in Wraparound String
- 【LeetCode】467. Unique Substrings in Wraparound String
- LeetCode 467. Unique Substrings in Wraparound String
- [leetcode]467. Unique Substrings in Wraparound String
- [LeetCode] 467. Unique Substrings in Wraparound String
- Leetcode:467. Unique Substrings in Wraparound String
- leetcode 467. Unique Substrings in Wraparound String
- [LeetCode]Unique Substrings in Wraparound String
- [leetcode 467]Unique Substrings in Wraparound String
- Leetcode-Unique Substrings in Wraparound String
- leetcode Unique Substrings in Wraparound String
- [Leetcode.467]Unique Substrings in Wraparound String
- [LeetCode]Unique Substrings in Wraparound String
- UVALive - 7544 Banking II 朴素dp、类似于背包的dp
- WAMP安装配置
- 141. Linked List Cycle
- 【深度学习:CNN】如何高效的通过BP算法来训练CNN
- c++ visitor 设计模式
- [LeetCode]467. Unique Substrings in Wraparound String
- 【UVA297】四象树(BZOJ2664)
- C++利用指针突破private
- android控制台灯
- 2.1 Toast(吐司)的基本使用
- 分苹果
- EntityFramework 简单入个门
- 关于验证码不显示,开了GD库也无法显示的解决方法。清除BOM头
- 在 Linux 上配置一个 syslog 服务器