循环单词

 

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.

注意事项

所有单词均为小写。

您在真实的面试中是否遇到过这个题?

Yes
样例

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 循环单词的更多相关文章

  1. 循环单词 java

    链接:https://www.nowcoder.com/questionTerminal/9d5fbe7750a34d0b91c73943f93b2d7d来源:牛客网如果一个单词通过循环右移获得的单词 ...

  2. LeetCode算法题-Longest Word in Dictionary(Java实现)

    这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...

  3. python习题一

    1.26个字母大小写成对打印,例如:Aa,Bb...... 方法1: for i in range(26): print(chr(65+i)+chr(97+i)) 方法2: for i in rang ...

  4. Python代码样例列表

    扫描左上角二维码,关注公众账号 数字货币量化投资,回复“1279”,获取以下600个Python经典例子源码 ├─algorithm│       Python用户推荐系统曼哈顿算法实现.py│    ...

  5. Java --本地提交MapReduce作业至集群☞实现 Word Count

    还是那句话,看别人写的的总是觉得心累,代码一贴,一打包,扔到Hadoop上跑一遍就完事了????写个测试样例程序(MapReduce中的Hello World)还要这么麻烦!!!?,还本地打Jar包, ...

  6. 利用 js 的一些函数调用,排序

    编辑器:Sublime Text 3 1.冒泡排序 let arr = new Array(5,9,3,6,7,8,4,2,);bubbleSort(arr);console.log(arr);fun ...

  7. 编写一段程序,从标准输入读取string对象的序列直到连续出现两个相同的单词或者所有单词都读完为止。使用while循环一次读取一个单词,当一个单词连续出现两次是使用break语句终止循环。输出连续重复出现的单词,或者输出一个消息说明没有人任何单词是重复出现的。

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  8. C 循环统计输入的单词个数和字符长度

    C 循环统计输入的单词个数和字符长度 #include <stdio.h> #include <Windows.h> int main(void) { ]; ; ; print ...

  9. Python3基础 str 循环输出list中每个单词及其长度

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. C# 委托系列(一)将方法作为方法的参数

    委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每 ...

  2. SharePoint2013之双语切换

    最近遇到个项目需要用SharePoint2013实现双语.看了篇老外的博客,经过项目经理的指点,终于算是搞定了(后面解释为什么说是"算是"). 在SharePoint2013中不像 ...

  3. LeetCode20.有效的括号 JavaScript

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...

  4. Knowledge Point 20180305 十进制转换成二进制浮点数

    如何将十进制的浮点数 转换二进制的浮点数,分为两部分: 1. 先将整数部分转换为二进制, 2. 将小数部分转换为二进制, 然后将整数部分与小数部分相加. 以 20.5 转换为例,20转换后变为1010 ...

  5. React Native开发中自动打包脚本

    React Native开发中自动打包脚本 在日常的RN开发中,我们避免不了需要将我们编写的代码编译成安装包,然后生成二维码,供需要测试的人员扫描下载.但是对于非原生的开发人员来说,可能不知如何使用X ...

  6. iOS11.2-11.3.1进行越狱及问题

    设备环境:Electra.iOS11.13.1 PS:Electra最新版本进行越狱只支持11.14以下的版本.同时这是不完美越狱,每次重启手机都需要重新越狱,最后,由于Electra版本推出仓促,一 ...

  7. fis3 安装(Linux)

    Linux安装fis3 1,首先安装node环境 https://segmentfault.com/a/1190000004245357 2,安装fis3 http://blog.csdn.net/g ...

  8. 第一个electron

    1 开发环境:node环境 2 下载electron:npm install electron --save-dev 3 package.json配置如下: { "name": & ...

  9. 分布式网上商城项目-solr搜索功能错误

    1.RuntimeException错误 java.lang.RuntimeException: org.apache.ibatis.binding.BindingException: Invalid ...

  10. 【解决】could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

    在同一套环境中跑了很多个项目都是用 docker-compose的方式启动的,导致创建的自定义网络过多出现下面的报错 Error response from daemon: could not fin ...