unique-substrings-in-wraparound-string(好)
https://leetcode.com/problems/unique-substrings-in-wraparound-string/
好,我自己做出来的。多总结规律,多思考。
package com.company; import java.util.HashMap;
import java.util.Map; class Solution {
public int findSubstringInWraproundString(String p) {
Map<Integer, Integer> mp = new HashMap<>();
int ret = 0;
int cur = 0;
char[] array = p.toCharArray();
if (array.length < 1) {
return 0;
}
for (int i=0; i<26; i++) {
mp.put(i, 0);
} ret++;
cur++;
mp.put(array[0]-'a', 1);
for (int i=1; i<array.length; i++) {
if ((array[i]-array[i-1]+26) % 26 == 1) {
cur++;
}
else {
cur = 1;
} if (cur > mp.get(array[i]-'a')) {
ret += cur - mp.get(array[i]-'a');
mp.put(array[i]-'a', cur);
}
}
return ret;
}
} public class Main { public static void main(String[] args) throws InterruptedException { String p = "zab"; Solution solution = new Solution();
int ret = solution.findSubstringInWraproundString(p); // Your Codec object will be instantiated and called as such:
System.out.printf("ret:%d\n", ret); System.out.println(); } }
unique-substrings-in-wraparound-string(好)的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [Swift]LeetCode467. 环绕字符串中唯一的子字符串 | Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- LeetCode 467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 【LeetCode】467. Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- 【LeetCode】467. Unique Substrings in Wraparound String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/unique-s ...
- 动态规划-独特的子字符串存在于Wraparound String总个数 Unique Substrings in Wraparound String
2018-09-01 22:50:59 问题描述: 问题求解: 如果单纯的遍历判断,那么如何去重保证unique是一个很困难的事情,事实上最初我就困在了这个点上. 后来发现是一个动态规划的问题,可以将 ...
- 467. [leetcode] Unique Substrings in Wraparound String
467. Unique Substrings in Wraparound String Implement atoi to convert a string to an integer. Hint: ...
- 467 Unique Substrings in Wraparound String 封装字符串中的独特子字符串
详见:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/ C++: class Solu ...
随机推荐
- MySQL 及 SQL 注入
如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题. 本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤SQL中注入的字符. 所谓SQL注入,就是 ...
- Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...
- 使用NPOI随意创建Excel(含下拉列表)
//创建工作簿 HSSFWorkbook ssfworkbook = new HSSFWorkbook(); //创建工作表(页) HSSFSheet sheet1 = ssfworkbook.Cre ...
- Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K To ...
- java.util.zip对zip文件解压
//通过构造方法,来创建一个新的ZIP输入流 ZipInputStream in = new ZipInputStream(new FileInputStream("G:/jquery.ca ...
- 一、安装JDK和Tomcat
一.安装JDK和Tomcat 1,安装JDK:直接运行jdk-7-windows-i586.exe可执行程序,默认安装即可. 备注:路径可以其他盘符,不建议路径包含中文名及特殊符号. 2.安装Tomc ...
- cvs版本控制器
CVS 版本控制器 首先我们要来明确 :为什么要学习CVS •项目开发靠的是一个团队的能力,很少有大中型项目是由个人完成的.对于团队开发来讲---能控制每个人的分工和权限, 可以让多个人同时编辑同 ...
- 创建FrameWork
1, http://blog.sina.com.cn/s/blog_407fb5bc01013v6s.html] 2,使用动态库 http://www.cocoachina.com/industry/ ...
- Shell脚本编程初体验
原文:http://linoxide.com/linux-shell-script/guide-start-learning-shell-scripting-scratch/ 作者: Petras L ...
- js友好提示是否继续,post提交
<script type="text/javascript"> function delcheck(qId,typeid) { if (!confirm('确定删除吗? ...