671 - 循環單詞

2017.9.28

首先判斷兩個字符串的長度是不是相同。然後判斷,字符串A兩個進行拼接後,是不是包含着字符串B,就表示是不是循環單詞了

public class Solution {
    /*
     * @param words: A list of words
     * @return: Return how many different rotate words
     */
	public int countRotateWords(List<String> words){
		int size = words.size();
		if(size <= 1){
			return size;
		}
		String []tmp = new String[size];
		int count = 0;
		for(String s : words){
			boolean flag = false;
			for(int i = 0; i <= count; i++){
				if(tmp[i] != null && tmp[i].length() == s.length()*2 && tmp[i].contains(s)){
					flag = true;
					break;
				}
			}
			if(flag == false){
				String add = s+s;
				tmp[count] = add;
				count++;
			}
			
		}
		return count;
	}
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章