686. Repeated String Match
来源:互联网 发布:java程序设计pdf下载 编辑:程序博客网 时间:2024/05/17 01:17
686. Repeated String Match
题目描述:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.
For example, with A = “abcd” and B = “cdabcdab”.
Return 3, because by repeating A three times (“abcdabcdabcd”), B is a substring of it; and B is not a substring of A repeated two times (“abcdabcd”).
题目大意:给定两个字符串A,B,判断A重复多少次,B会变为其的子串,如果无解,返回-1。
思路:使用StringBulider
代码
class Solution { public int repeatedStringMatch(String A, String B) { int count = 0; StringBuilder stringBuilder = new StringBuilder(); while (stringBuilder.length() < B.length()) { stringBuilder.append(A); count++; } if (stringBuilder.toString().contains(B)) { return count; } if(stringBuilder.append(A).toString().contains(B)) return ++count; return -1; }}
阅读全文
0 0
- 686. Repeated String Match
- 686. Repeated String Match
- leetcode 686. Repeated String Match
- leetcode 686. Repeated String Match
- [LC]686. Repeated String Match
- leetcode 686. Repeated String Match
- 【LeetCode】686. Repeated String Match
- leetcode 686. Repeated String Match
- Leetcode-686. Repeated String Match(string)
- LWC 52:686. Repeated String Match
- Leetcode | Repeated String Match
- leetcode 686 Repeated String Match
- leetcode题解-686. Repeated String Match && 38. Count and Say
- Repeated String Match问题及解法
- leetcode_686.Repeated String Match ? 待解决
- LeetCode Weekly Contest 52 Repeated String Match(string)
- Leetcode挑战题——Repeated String Match
- String:459. Repeated Substring Pattern
- jquery easyui-tree 单击文字无法展开菜单
- mysql数据库数据类型之字符型
- java--生成6位序列号
- PHP 数字字母图片验证码输出功能
- Neural Style Transfer
- 686. Repeated String Match
- 编写代码之原则总结_MD
- 模型调参:超参调节tips总结
- jquery
- 【数据挖掘算法】关联分析——Apriori算法
- java--模拟网站有三次登陆机会
- 重要的算法思想
- Matlab学习小结
- 使用treeNMS管理及监控Redis