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(好)的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  3. [Swift]LeetCode467. 环绕字符串中唯一的子字符串 | Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  4. 467. Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  5. LeetCode 467. Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  6. 【LeetCode】467. Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  7. 【LeetCode】467. Unique Substrings in Wraparound String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/unique-s ...

  8. 动态规划-独特的子字符串存在于Wraparound String总个数 Unique Substrings in Wraparound String

    2018-09-01 22:50:59 问题描述: 问题求解: 如果单纯的遍历判断,那么如何去重保证unique是一个很困难的事情,事实上最初我就困在了这个点上. 后来发现是一个动态规划的问题,可以将 ...

  9. 467. [leetcode] Unique Substrings in Wraparound String

    467. Unique Substrings in Wraparound String Implement atoi to convert a string to an integer. Hint: ...

  10. 467 Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    详见:https://leetcode.com/problems/unique-substrings-in-wraparound-string/description/ C++: class Solu ...

随机推荐

  1. 约瑟夫问题 java

    约瑟夫环:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列;他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围 ...

  2. android 代码整体回退

    repo forall -c 'HAHA=`git log --before="3 days" -1 --pretty=format:"%H"`;git res ...

  3. 一个通用的DAO模型实现增删改查

    首先三个架包: mysql-connector-java-jar commons-dbcp-1.4jar commons-pool-1.5.5jar 导进去: (从上往下一次调用,实现功能) ---- ...

  4. selenium帮助手册以及 webdriver的各种driver

    帮助手册 http://selenium-python.readthedocs.io/locating-elements.html 转载于:http://blog.csdn.net/five3/art ...

  5. QT笔记之模态对话框及非模态对话框

    模态对话框(Modal Dialog)与非模态对话框(Modeless Dialog)的概念不是Qt所独有的,在各种不同的平台下都存在.又有叫法是称为模式对话框,无模式对话框等.所谓模态对话框就是在其 ...

  6. UVA10339 Watching Watches

    题目大意:有两个表,每天都会慢一点时间,给出每天慢得秒数,问下一次重合的时刻. 解题思路:时刻重合也就是说整整差了一周,一周是12小时,用12小时的秒数除以两个表的相差那就是需要多少天的时间后重合,知 ...

  7. 转Masonry遇到的问题

    1,ImageView 圆角: 解决方法如下: https://github.com/SnapKit/Masonry/issues/153 2,iphone4  tableview只显示一半 加了一个 ...

  8. ECharts开始

    为ECharts准备一个具备大小(宽高)的Dom(当然可以是动态生成的) //from echarts example <body> <div id="main" ...

  9. C#For循环

    for循环基本格式 for(初始条件;循环条件;状态改变) { 循环体 } 1.小明单位发了100元的购物卡,小明到超市买三类洗化用品,洗发水(15元),香皂(2元),牙刷(5元).要把100元整好花 ...

  10. 用PyAIML开发简单的对话机器人

    AIML files are a subset of Extensible Mark-up Language (XML) that can store different text patterns ...