LintCode 671 循环单词
来源:互联网 发布:淘宝化妆品店铺简介 编辑:程序博客网 时间:2024/06/06 14:08
The words are same rotate words if rotate the word to the right by loop, and get another. Count how many different rotate word sets in dictionary.
E.g. picture and turepic are same rotate words.
["picture", "turepic", "icturep", "word", "ordw", "lint"]return 3.
“picture”, “turepic”, “icturep” are same ratote words.
“word”, “ordw” are same too.
“lint” is the third word that different from the previous two words.
将每个String的变化串加进Set集合中,进行重复判断。
解一:
//671循环单词 public static int countRotateWords(List<String> words){ int count=0; Set<String> set=new HashSet<String>(); for (int i = 0; i < words.size(); i++) { String string=words.get(i); if (!set.contains(string)) { count++; set.add(string); String b=change(string); while(!b.equals(string)){ set.add(b); b=change(b); } } } return count; } public static String change(String string){ String aString=string.substring(string.length()-1) +string.substring(0,string.length()-1); return aString; }
阅读全文
0 0
- LintCode 671 循环单词
- LintCode 循环单词
- 循环单词-LintCode
- LintCode-关于一次遍历解决循环单词问题的思考
- LintCode 最长单词
- lintcode-单词搜索-123
- lintcode-单词接龙-120
- 最长单词(LintCode)
- LintCode- 单词切分
- lintcode ----最长单词
- lintcode ----单词搜索
- LintCode 单词切分
- LintCode 单词搜索 II
- LintCode : 单词搜索 II
- lintcode,单词切分
- lintcode,单词搜索
- lintcode,单词接龙
- LintCode 133 最长单词
- 小白学习微信小程序指南
- OpenCV基于傅里叶变换以及霍夫直线检测的旋转文本校正
- Visio| Visio简易使用指南
- 机器学习之决策树学习笔记
- RaspberryPi树莓派安装MySQL并远程登录
- LintCode 671 循环单词
- CTO 离职、研发变动,百度外卖与饿了么组织架构融合公布
- Problem J: C/C++经典程序训练5---图形打印问题
- Linux系统下的SSH服务器的搭建
- Java反射基础
- matlab simulink保存出错的问题
- 欢迎使用CSDN-markdown编辑器
- 指针常量,常量指针,指针 区别
- Ubuntu 需要安装软件地址记录