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)==和equals()的使用小结

    1.如果两个变量说基本数据类型,且都是数值类型,eg.65f,65(不一定要求数据类型严格相同),只要两个变量的值相等,就将返回true int it=65; float fl=65.0f; char ...

  2. Python中的变量、引用、拷贝和作用域

    在Python中,变量是没有类型的,这和以往看到的大部分编辑语言都不一样.在使用变量的时候,不需要提前声明,只需要给这个变量赋值即可.但是,当用变量的时候,必须要给这个变量赋值:如果只写一个变量,而没 ...

  3. html里文本保留换行格式

    用<pre></pre>把文本包起来

  4. Android网络通信之WiFi Direct

    使用Wi-Fi Direct技术可以让具备硬件支持的设备在没有中间接入点的情况下进行直接互联.Android 4.0(API版本14)及以后的系统都提供了对Wi-Fi Direct的API支持.通过对 ...

  5. 20150629_Andriod_06_插入_删除_弹出式操作数据

    Fr_06_view_s6 --> activity_f6_insert              --> activity_f7__delete ******************** ...

  6. ArrayList实现原理

    转载:http://wiki.jikexueyuan.com/project/java-collection/arraylist.html ArrayList 概述 ArrayList 可以理解为动态 ...

  7. Entity Framework 第五篇 状态跟踪

    本人建议尽量使用EntityState来表名Entry的状态,而不要使用Configuration.AutoDetectChangesEnabled自动状态跟踪,为什么我这么建议呢?他们到底有什么异同 ...

  8. 让VS自动生成我们自己的注释

    1. 找到你VS的安装目录:C:\Program Files (x86)\Microsoft Visual Studio 11.0 2. 在VS安装路径下依次找到这些文件夹:\Common7\IDE\ ...

  9. 零零碎碎写的shell脚本(三):一键自动归档压缩脚本

    #!/bin/bash # author by sysk read -p "There files: " FILE1 FILE2 FILE3 read -p "Desti ...

  10. flume ng系列之——flume安装

    flume版本:1.5.0 1.下载安装包: http://www.apache.org/dyn/closer.cgi/flume/1.5.0/apache-flume-1.5.0-bin.tar.g ...