Question:

For each word, you can get a list of neighbor words by calling getWords(String), find all the paths from word1 to word2.

 public class Solution {
List<List<String>> finalList = new ArrayList<>(); public static void main(String[] args) {
Solution s = new Solution();
System.out.println(s.getPath("face", "book"));
} public List<List<String>> getPath(String s, String e) {
List<String> list = new ArrayList<String>();
helper(s, e, list, new HashSet<String>());
return finalList;
} public void helper(String s, String e, List<String> list, Set<String> set) {
if (set.contains(s) || (list.size() != && list.get(list.size() - ).equals(e))) return;
list.add(s);
set.add(s); if (s.equals(e)) {
finalList.add(new ArrayList<String>(list));
} List<String> dicts = getWords(s);
for (String str : dicts) {
helper(str, e, list, set);
} list.remove(s);
set.remove(s);
} public List<String> getWords(String str) {
List<String> list1 = new ArrayList<String>(); if (str.equals("face")) {
list1.add("foce");
list1.add("fack");
} else if (str.equals("foce")) {
list1.add("face");
list1.add("fook");
} else if (str.equals("fack")) {
list1.add("fook");
list1.add("faok");
} else if (str.equals("fook")) {
list1.add("fack");
list1.add("book");
} else if (str.equals("faok")) {
list1.add("foce");
list1.add("book");
}
return list1;
}
}

word to word的更多相关文章

  1. Microsoft.Office.Interop.Word 创建word

    Microsoft.Office.Interop.Word 创建word 转载:http://www.cnblogs.com/chenbg2001/archive/2010/03/14/1685746 ...

  2. reverse the string word by word

    题目:Given an input string, reverse the string word by word. For example,Given s = "the sky is bl ...

  3. LeetCode 5:Given an input string, reverse the string word by word.

    problem: Given an input string, reverse the string word by word. For example: Given s = "the sk ...

  4. C#用Microsoft.Office.Interop.Word进行Word转PDF的问题

    之前用Aspose.Word进行Word转PDF发现'\'这个字符会被转换成'¥'这样的错误,没办法只能换个方法了.下面是Microsoft.Office.Interop.Word转PDF的方法: p ...

  5. 17. Word Break && Word Break II

    Word Break Given a string s and a dictionary of words dict, determine if s can be segmented into a s ...

  6. 18. Word Ladder && Word Ladder II

    Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transform ...

  7. leetcode@ [139/140] Word Break & Word Break II

    https://leetcode.com/problems/word-break/ Given a string s and a dictionary of words dict, determine ...

  8. leetcode@ [79/140] Trie树应用 Word Search / Word Search II

    https://leetcode.com/problems/word-search/ class Solution { public: struct Trie{ Trie *next[]; bool ...

  9. C# 操作 Word 修改word的高级属性中的自定义属性2

    word的类库使用的是word2007版本的类库,类库信息见下面图片,折腾了半天,终于找到入口,网上 很多说的添加或者修改word的高级属性中的自定义属性都是错误的,感觉都是在copy网上的代码,自己 ...

随机推荐

  1. Yii2 – 如何写一个插件 , 如何做一个扩展

    原文地址: http://www.fancyecommerce.com/2016/05/10/yii2-%E5%A6%82%E4%BD%95%E5%86%99%E4%B8%80%E4%B8%AA%E6 ...

  2. mysql存储过程对900w数据进行操作测试

    新增索引:LTER TABLE `tablename` ADD INDEX `sdhid` (`createTime`) USING BTREE ;[SQL]ALTER TABLE `tablenam ...

  3. CSS样式表继承详解

    最近在恶补css样式表的基础知识.上次研究了css样式表之冲突问题详解 .这次是对 css 继承 特性的学习. 什么是css 继承?要想了解css样式表的继承,我们先从文档树(HTML DOM)开始. ...

  4. php函数mt_rand和rand 速度测试

    今天在写代码时,看到以前的同时写了一个取随机数,用到了mt_rand(2,19) 就顺手搜了一下,mt_rand和rand的区别. 先看官方的解释 mt_rand 和 rand mt_rand — 生 ...

  5. nginx -s reload失败

    在重启nginx时报错误. wangkongming@ThinkPad-T410 ~ $ sudo /usr/sbin/nginx -s reload nginx: [error] invalid P ...

  6. Sublime Text3

    Sublime Text3 激活码: ----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E- 813A03DD 5E4AD9E ...

  7. javascript 数据类型转换

    javascrīpt 类型转换函数 在Javascrīpt中,Double类型和Int类型都是看作为Number对象. 1.Number转成String number.toString() Strin ...

  8. jquery+css3实现3d滚动旋转

    最近有个漂亮妹子一直在向我推销潭州的视频,BUT我以前就看了一次觉得挺水的,就对那个妹子表示吾孤高.你们那玩意没意义的很弱.然后那个漂亮妹子锲而不舍的对我发链接,这个效果会吗,这个幻灯会写吗...我也 ...

  9. 2015年11月26日 Java基础系列(四)class的定义,继承和实现interface

    序,类的设计是JAVA操作的核心,面对对象思想中一切皆对象. 一.类定义中的变量 静态成员变量,为类所有,称为类变量:只有一份,编译时即分配值,使用关键字static声明. 非静态成员变量,每个实例一 ...

  10. 自动去除nil的NSDictionary和NSArray构造方法

    http://www.jianshu.com/p/a1e8d8d579c7 极分享 http://www.finalshares.com/