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. Python之路【第七篇续】:进程、线程、协程

    Socket Server模块 SocketServer内部使用 IO多路复用 以及 “多线程” 和 “多进程” ,从而实现并发处理多个客户端请求的Socket服务端.即:每个客户端请求连接到服务器时 ...

  2. javascript Date 总结

    构造函数 Date 对象的构造函数有以下4种: (1)var variable = new Date(); (2)var variable = new Date(millisenconds); (3) ...

  3. css3d总结

    3d舞台 设置 perspective(景深): length, 可以设置overflow:hidden 3d舞台下 -> 3d元素容器  设置 transform-style: preserv ...

  4. 关于Xcode7更新之后使用 SDWebImage 图片加载不出来

    解决方法:在Info.plist中添加NSAppTransportSecurity类型Dictionary. 在NSAppTransportSecurity下添加NSAllowsArbitraryLo ...

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

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

  6. editplus中使用emmet?

    要用emmet生成html类型, 格式是: html:???, 意思是 都是html大类型, 小类型用冒号. 如:html:5, 或者全部都是! 则生成html5的类型文档. emmet是zen co ...

  7. 再说vim的tab设置

    首先, vim的设置允许简写 // 单击一次tab,停靠, 停止在 4个spaces距离处 set tabstop=4 , 可以简写为: set ts=4 // 允许将tab转换为空格 turn ta ...

  8. thinkphp- 许愿墙-1

    控制器的方法, 要显示的模板默认的跟方法名相同. 也可以不同, 但应该 仍然是对应文件夹下的html模板文件: $this->display('其他的模板html文件名, 不用加html扩展名' ...

  9. TP框架整合Swagger UI接口文档

    1.下载swagger ui:http://swagger.io/swagger-ui/: 2.在应用目录里新建一个目录xxx:如图 3.解压后把dist目录的所有文件拷贝到新建的目录里面: 4.在新 ...

  10. RTX二次开发(一)(基于ASP.NET)

    腾讯通RTX是(Real Time eXpert)是腾讯公司推出的企业级实时通信平台,致力于帮助企业提高运作效率.降低沟通成本.拓展商业机会,是一种高度可管理.低成本.易部署的IT平台.RTX集成了丰 ...