word to word
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的更多相关文章
- Microsoft.Office.Interop.Word 创建word
Microsoft.Office.Interop.Word 创建word 转载:http://www.cnblogs.com/chenbg2001/archive/2010/03/14/1685746 ...
- reverse the string word by word
题目:Given an input string, reverse the string word by word. For example,Given s = "the sky is bl ...
- 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 ...
- C#用Microsoft.Office.Interop.Word进行Word转PDF的问题
之前用Aspose.Word进行Word转PDF发现'\'这个字符会被转换成'¥'这样的错误,没办法只能换个方法了.下面是Microsoft.Office.Interop.Word转PDF的方法: p ...
- 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 ...
- 18. Word Ladder && Word Ladder II
Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transform ...
- 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 ...
- leetcode@ [79/140] Trie树应用 Word Search / Word Search II
https://leetcode.com/problems/word-search/ class Solution { public: struct Trie{ Trie *next[]; bool ...
- C# 操作 Word 修改word的高级属性中的自定义属性2
word的类库使用的是word2007版本的类库,类库信息见下面图片,折腾了半天,终于找到入口,网上 很多说的添加或者修改word的高级属性中的自定义属性都是错误的,感觉都是在copy网上的代码,自己 ...
随机推荐
- C#程序
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- [Mongodb]删除指定字段
摘要 如果想要删除mongodb中一个document的某个字段,该如何做呢? 方法模版 db.user.update({"email_state":{"$exists& ...
- Struts2验证框架实例
今天写了个Struts验证框架的实例,总算把验证框架弄清楚了. 上一篇Struts实例的action没有继承ActionSupport类,虽然也可以实现action的功能,但是却不能应用Struts提 ...
- C#反射机制(转)
一:反射的定义 审查元数据并收集关于它的类型信息的能力.元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建一个类定义表,一个字段定义表,和一个方法定义表等. Sys ...
- Linux服务器管理: 系统的进程管理pstree命令
pstree命令是查看进程树或者结构的命令 [root@localhost~]#pstree [选项] 需要注意的是不能将 -p和-u同时使用 如果同时使用前者生效后者无效但并不报错 选项: -p: ...
- gtest
一.安装配置 1.简介 2.安装 下载地址: https://code.google.com/p/googletest/downloads/list 解压安装: unzip gtest-1.7.0.z ...
- iOS原生的搜索:UISearchController
iOS8之前我们使用UISearchDisplayController做TableView的本地搜索,查看UIKit库,苹果已经使用新控件取代它. NS_CLASS_DEPRECATED_IOS(3_ ...
- ML—随机森林·1
Introduction to Random forest(Simplified) With increase in computational power, we can now choose al ...
- Codeforces Round #202 (Div. 2) A,B
A. Cinema Line time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- poj 3744 Scout YYF I(概率dp,矩阵优化)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5020 Accepted: 1355 Descr ...