lintcode671 循环单词
循环单词
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.
注意事项
所有单词均为小写。
Given dict =["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.
class Solution {
public:
/*
* @param words: A list of words
* @return: Return how many different rotate words
*/
int countRotateWords(vector<string> words) {
// Write your code here
if (words.empty()) return ;
int count = words.size();
bool *flag = new bool[count];
memset(flag, false, count);
for (int i = ; i < count - ; i++) {
if (flag[i] == true) {
continue;
}
for (int j = i + ; j < count; j++) {
if (isSame(words[i], words[j])) {
flag[j] = true;
}
}
}
for (int i = ; i < words.size(); i++) {
if (flag[i]) {
count--;
}
}
return count;
}
bool isSame(string wordi, string wordj) {
if (wordi.length() != wordj.length()) {
return false;
}
wordi = wordi + wordi;
if (wordi.find(wordj) != string::npos) {
return true;
} else {
return false;
}
}
};
lintcode671 循环单词的更多相关文章
- 循环单词 java
链接:https://www.nowcoder.com/questionTerminal/9d5fbe7750a34d0b91c73943f93b2d7d来源:牛客网如果一个单词通过循环右移获得的单词 ...
- LeetCode算法题-Longest Word in Dictionary(Java实现)
这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...
- python习题一
1.26个字母大小写成对打印,例如:Aa,Bb...... 方法1: for i in range(26): print(chr(65+i)+chr(97+i)) 方法2: for i in rang ...
- Python代码样例列表
扫描左上角二维码,关注公众账号 数字货币量化投资,回复“1279”,获取以下600个Python经典例子源码 ├─algorithm│ Python用户推荐系统曼哈顿算法实现.py│ ...
- Java --本地提交MapReduce作业至集群☞实现 Word Count
还是那句话,看别人写的的总是觉得心累,代码一贴,一打包,扔到Hadoop上跑一遍就完事了????写个测试样例程序(MapReduce中的Hello World)还要这么麻烦!!!?,还本地打Jar包, ...
- 利用 js 的一些函数调用,排序
编辑器:Sublime Text 3 1.冒泡排序 let arr = new Array(5,9,3,6,7,8,4,2,);bubbleSort(arr);console.log(arr);fun ...
- 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。
// test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- C 循环统计输入的单词个数和字符长度
C 循环统计输入的单词个数和字符长度 #include <stdio.h> #include <Windows.h> int main(void) { ]; ; ; print ...
- Python3基础 str 循环输出list中每个单词及其长度
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
随机推荐
- 基于vue脚手架的项目打包上线(发布)方法和误区
最近要把vue脚手架开发的一个项目上线,只知道vue脚手架是基于node的服务端项目,那么只需要 npm run dev 就可以轻松启动整个项目,当我想当然的给服务器配置合适的node环境(这里也遇到 ...
- DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载 吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...
- Head First Java学习笔记
1.基本概念 1.1.工作方式 源代码(.java)---编译器(执行javac程序)---产生字节码(.class与平台无关)---JAVA虚拟机(JVM,读取与执行字节码) 1.2.汇编语言是对基 ...
- php-预定义
php预定义异常 Exception是所有异常的基类 属性 message:异常消息内容 code:异常代码 file:抛出异常的文件名 line:抛出异常在该文件的行号 ErrorException ...
- 【算法笔记】B1010 一元多项式求导
1010 一元多项式求导 (25 分) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为nxn−1.) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 ...
- 遗传算法详解及c++实现
1.什么是遗传算法? 遗传算法是模拟达尔文生物进化论的自然选择和遗传学机理的生物进化过程的计算模型,是一种通过模拟自然进化过程搜索最优解的方法.遗传算法是从代表问题可能潜在的解集的一个种群开始的,而一 ...
- kali linux 安装 Mysql Can't read from messagefile 报错解决方案
1.下载安装包 下载地点:https://dev.mysql.com/downloads/mysql/ 或者 wget http://dev.mysql.com/get/Downloads/MySQL ...
- 463. Island Perimeter (5月29日)
解答 class Solution { public: int islandPerimeter(vector<vector<int>>& grid) { int num ...
- [MYSQL][1]创建,修改,删除表
查看有哪些数据库: SHOW DATABASES; 创建,删除数据库: CREATE DATAABASE mydb; DROP DATABASE mydb; 查看有哪些表: SHOW TABLES; ...
- javascript 时间倒计时效果
<div id="divdown1"></div> <script language="javascript" type=&quo ...