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. 捕获EF提交异常

    try { } catch (DbEntityValidationException dbex) { string errMsg = string.Empty; foreach (var eve in ...

  2. linux 下 ls 文件夹和文件没有颜色的解决办法

    .bashrc 中加入 alias ls="ls --color"

  3. 【转】【Java】利用反射技术,实现对类的私有方法、变量访问

    java关于反射机制的包主要在java.lang.reflect中,structs,hibernate,spring等框架都是基于java的反射机制. 下面是一个关于利用java的反射机制,实现了对私 ...

  4. python- shutil 高级文件操作

    简介 shutil模块提供了大量的文件的高级操作.特别针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作.对单个文件的操作也可参见os模块. 拷贝文件 shutil.copyfile(src, ...

  5. Sql2008R2设置远程链接

    下边的文章是从百度经验里粘过来的.. 经过测试确实有效..留个备份.. 有个小情况在前边说一下.. 在操作前一定要确定自己的sa用户密码是不是一样..不要以为自己知道的是对的就直接略过某些步骤.. 俗 ...

  6. ehcache memcache redis 三大缓存男高音

    最近项目组有用到这三个缓存,去各自的官方看了下,觉得还真的各有千秋!今天特意归纳下各个缓存的优缺点,仅供参考!  Ehcache 在java项目广泛的使用.它是一个开源的.设计于提高在数据从RDBMS ...

  7. start: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart:

    用Ubuntu远程登录虚拟host时出现:    start: Unable to connect to Upstart: Failed to connect to socket /com/ubunt ...

  8. 使用cachemanager做缓存(Session的缓存)

    1.我在这里直接用 cachemanager.redis 往redis里面存储缓存数据2.步骤 1)下载CacheManager.Redis(包含了CacheManager.Core) 下载Stack ...

  9. acpi和btrfs-安装opensuse时的选项

    g-------------------- 关于GPL和LGPL和QPL等 读书笔记:采用LGPL的代码,一般情况下它本身就是一个第三方库(别忘了LGPL最早的名字就是Library GPL),这时候 ...

  10. 总结——R中查看属性的函数

    本文原创,转载注明出处,本人Q1273314690 R中知道一个变量的主要内容和结构,对我们编写代码是很重要的,也可以帮我们避免很多错误. 但是,R中有好几个关于属性查看的函数,我们往往不知道什么时候 ...