首页 > 其他 > 详细

LeetCode 466

时间:2020-04-19 11:30:48      阅读:46      评论:0      收藏:0      [点我收藏+]

https://leetcode-cn.com/problems/count-the-repetitions/

每日一题系列。

暴力解即可完成,我自己傻逼了开了个stringbuilder去存完整的s1字符串,导致最后炸了。

后来优化后就过了,打败31%的人 算是过了吧。

class Solution {
    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
        char[] str1 = s1.toCharArray();
        char[] str2 = s2.toCharArray();
        int count1 = 0;
        int count2 = 0;
        int j = 0;
        while(count1 < n1){
            for (char c : str1) {
                if (c == str2[j]) {
                    j++;
                    if (j == str2.length) {
                        count2++;
                        j = 0;
                    }
                }
            }
            count1++;
        }
        return count2/n2;
    }
}

 

LeetCode 466

原文:https://www.cnblogs.com/ZJPaang/p/12730710.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!