1. 题目链接

  2. 题意
    • 定义一个特殊的串, 现在给出串S1和S2的参数, 问: S2最多可以多少个连接起来扔是S1的子序列, 求出这个最大值
  3. 解题思路
    • 注意s1与S1的区别, 可以去看题目描述, 预处理出s1从s2的每一个字符开始匹配, s1可以匹配到s2串尾的数量, 即如果从s2的当前下标开始匹配, 这一个s1最多可以匹配多少s2, 这个s1匹配完成后匹配到了s2的哪一个字符, 下一个s1匹配s2的话应该从哪一个下标开始, 因为串长最长100, 这个预处理时间消耗是很少的, 有了这个预处理的结果, 我们就可以O(n)的知道S1可以匹配多少个s2, 进而推算出匹配多少个S2.
  4. AC代码
    class Solution {
    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
    int answer = 0; ArrayList<Integer> numArrayList = new ArrayList<Integer>();
    ArrayList<Integer> idxArrayList = new ArrayList<Integer>(); for(int i = 0; i < s2.length(); ++i) {
    int num = 0, idx = i;
    for(int j = 0; j < s1.length(); ++j) {
    if(s2.charAt(idx) == s1.charAt(j)) {
    idx++;
    if(idx == s2.length()) {
    num++;
    idx = 0;
    }
    }
    }
    numArrayList.add(num);
    idxArrayList.add(idx);
    } int idx = 0; for(int i = 0; i < n1; ++i) {
    answer += numArrayList.get(idx);
    idx = idxArrayList.get(idx);
    } return answer / n2;
    }
    }

LeetCode466. Count The Repetitions的更多相关文章

  1. CH5702 Count The Repetitions

    题意 5702 Count The Repetitions 0x50「动态规划」例题 描述 定义 conn(s,n) 为 n 个字符串 s 首尾相接形成的字符串,例如: conn("abc& ...

  2. [Swift]LeetCode466. 统计重复个数 | Count The Repetitions

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  3. 466. Count The Repetitions

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  4. [LeetCode] Count The Repetitions 计数重复个数

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  5. Leetcode: Count The Repetitions

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

  6. CH5702 Count The Repetitions[倍增dp]

    http://contest-hunter.org:83/contest/0x50%E3%80%8C%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E3%80%8D%E4%B ...

  7. 【leetcode 字符串】466. Count The Repetitions

    https://leetcode.com/problems/count-the-repetitions/description/ 找循环节 https://www.cnblogs.com/grandy ...

  8. 第七周 Leetcode 466. Count The Repetitions 倍增DP (HARD)

    Leetcode 466 直接给出DP方程 dp[i][k]=dp[i][k-1]+dp[(i+dp[i][k-1])%len1][k-1]; dp[i][k]表示从字符串s1的第i位开始匹配2^k个 ...

  9. [LeetCode] 466. Count The Repetitions 计数重复个数

    Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc&qu ...

随机推荐

  1. ArcSDE数据库、文件地理数据库和个人地理数据库的区别

    Geodatabase地理数据库分为: Personal Geodastabase个人地理数据库, File Geodatabase文件地理数据库, ArcSDE Geodatabase SDE地理数 ...

  2. class-dump的安装和使用

    安装步骤 1.下载地址:http://stevenygard.com/projects/class-dump/ 2.打开终端输入 open /usr/local/bin 3.把dmg文件中的class ...

  3. 深入理解NIO(三)—— NIO原理及部分源码的解析

    深入理解NIO(三)—— NIO原理及部分源码的解析 欢迎回到淦™的源码看爆系列 在看完前面两个系列之后,相信大家对NIO也有了一定的理解,接下来我们就来深入源码去解读它,我这里的是OpenJDK-8 ...

  4. ArrayList中的Iterator详解

    每个实现Iterable接口的类必须提供一个iterator方法,返回一个Iterator对象,ArrayList也不例外 public Iterator<E> iterator() { ...

  5. python使用镜像源安装库

    pip install django -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 豆瓣 :http://pypi.d ...

  6. linux中的bash

    一.bash的简介 操作系统都是需要通过shell跟内核来交互的,常见的shell有GUI.KDE.sh.csh.bash.tsh.zsh等. 而linux中最常用的shell就是bash. 二.ba ...

  7. 2288: 【基础】小X转进制

    2288: [基础]小X转进制 时间限制: 1 Sec 内存限制: 256 MB 提交: 1316 解决: 576 [提交] [状态] [讨论版] [命题人:ghost79] 题目描述 小X喜欢研究进 ...

  8. 一文教会你如何在 Spring 中进行集成测试,太赞了

    不得不说,测试真的是太重要了!但并不是所有的开发者都这样认为,这种感觉在我回到洛阳后尤其强烈.竟然有团队成员不经测试就把代码提交到代码库,并且是会报错的那种,我天呐,遇到这种队友我也是醉了. 我之前是 ...

  9. Light of future-冲刺Day 1

    目录 归属班级 →2019秋福大软件工程实践Z班 作业要求 →团队作业第五次-项目冲刺 团队名称 未来之光 这个作业的目标 第一天的冲刺总结 作业正文 →Light of future-冲刺Day 1 ...

  10. Visual Studio Code 1.44 设置简体中文界面语言(小白图文教程)

    作为一款微软出品的编辑器,安装完毕后,默认界面竟然不是中文!而更“丧心病狂”的是菜单里竟然连“设置”或“设置语言”这种PC软件常见选项也没有!!这种设计对小白而言简直 反!!!人!!!类!!! (默认 ...