671
来源:互联网 发布:夏易网络官网 编辑:程序博客网 时间:2024/05/12 19:16
2017.9.9
判断两个字符串是不是循环单词。
public static boolean isSame(String str1, String str2){
if(str1.length() != str2.length()){
return false;
}
str1 = str1.concat(str1);
if(str1.contains(str2)){
return true;
}
else{
return false;
}
}
先将str1 两遍加起来。
在判断新的str1 是不是contain str2。
刚开始理解错了,以为只要是字母的组合一致就可以,其实还要考虑是不是循环。
public class Solution { /* * @param words: A list of words * @return: Return how many different rotate words */ public static int countRotateWords(List<String> words) { // Write your code hereif(words.isEmpty()){return 0;}int count = words.size();Object []str = words.toArray();boolean []flag = new boolean[count];for(int i = 0; i< count - 1; i++){if(flag[i] == true){continue;}String str1 = str[i].toString();for(int j = i+1; j < count; j++){String str2 = str[j].toString();if(isSame(str1,str2) == true){flag[j] = true;}}}for(int i = 0;i< words.size(); i++){if(flag[i] == true){count--;}}return count;}public static boolean isSame(String str1, String str2){if(str1.length() != str2.length()){return false;}str1 = str1.concat(str1);if(str1.contains(str2)){return true;}else{return false;}}}
阅读全文
0 0
- 671
- 671
- codeforces 671B
- codeforces 671B
- codeforces 671A
- Codeforces 671B 二分
- LintCode 671 循环单词
- Testinside 646-671考题下载
- 多项式【数据结构课设一枚,671原创】
- Codeforces 671A Recycling Bottles
- codeforces 671A Recycling Bottles
- codeoforces 671B Robin Hood
- CodeForces 671B Robin Hood
- cf 671B Robin Hood
- CodeForces 671A Recycling Bottles
- 转载于[671coder的专栏]
- TC SRM 671 Div2 500 BearDartsDiv2
- TC SRM 671 Div2 1000 BearDestroysDiv2
- FreeCodeCamp问题汇总
- sas统计分析学习笔记(九)——方差分析
- Centos6.8 软Raid实践
- [BZOJ]1924: [Sdoi2010]所驼门王的宝藏 强连通+DP
- 高精度乘法
- 671
- ThreadLocal深入解析
- 声明
- 如何方便的对Matlab中的代码进行版本管理
- java 多线程 匿名内部类
- Pycharm及Python安装详解
- 像程序员一样思考
- 图的存储结构
- SQL server 多表联合查询