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. SlickGrid example 3a: 可编辑单元

    可编辑单元支持一列展示多个属性域,可以为编辑单元提供验证,并且自定义验证事件.   代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 T ...

  2. Humble Numbers

    Humble Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9988 Accepted: 4665 Descri ...

  3. Animator组件关闭再打开后参数丢失问题

    问题如下,因为再激活Animator时,它会重置一次,参数也会丢失 这个问题一直存在,论坛给出的解释是把参数缓存下来,在激活时重置 http://answers.unity3d.com/questio ...

  4. Mysql任务调度

    Mysql任务调度 Event调度配置 Mysql任务调度Event不执行 Mysql任务作业Event不执行 我采用的方法就是: 方法一:找到当前使用的 .cnf 文件,在 [mysqld] 的下面 ...

  5. 电量检测芯片BQ27510使用心得

    最近接触到一款TI的电量检测芯片BQ27510,网上很少有人提及该芯片如何使用,大部分博文都是搬得BQ27510的datasheet,至于真正使用过的很少,该芯片我个人感觉还是非常强大的,能自动学习你 ...

  6. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  7. MySql使用show processlist查看正在执行的Sql语句

    今天上班例行的查看了下服务器的运行状况,发现服务器特卡,是mysqld这个进程占用CPU到了99%导致的. 比较好奇是那个程序在使用mysql导致cpu这么高的,通过show processlist命 ...

  8. 针对各种浏览器css不兼容的写法

    /*针对谷歌浏览器内核支持的CSS样式*/@media screen and (-webkit-min-device-pixel-ratio:0) { 样式 } /*针对IE6特制识别的CSS样式*/ ...

  9. sqlmap基本命令

    ./sqlmap.py –h //查看帮助信息./sqlmap.py –u “http://www.anti-x.net/inject.asp?id=injecthere” //get注入./sqlm ...

  10. 安装 slowhttptest ddos攻击软件

    kali:apt-get install slowhttptest