- 博客(7)
- 收藏
- 关注
原创 2021-06-18
输入:words = ["smooth","common","moorings"]输出:"moo",其他如 "omo", "oom" 也是正确答案。解释:m 在 "smooth" 中出现 1 次,在 "common" 中出现 2 次,在 "moorings" 中出现 1 次,所以只有 1 个 m 符合要求。o 在 "smooth" 中出现 2 次,在 "common" 中出现 2 次,在 "moorings" 中出现 2 次,所以 2 个 o 均符合要求。其他字符没有在 words 的每个字符串中
2021-06-18 00:05:34 582
原创 [LeetCode] Word Ladder 词语阶梯 BFS
class Solution {public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { unordered_set<string> wordSet(wordList.begin(), wordList.end()); if (!wordSet.count(endWord)) return 0; uno.
2021-05-03 17:09:21 69
原创 Python 读取文本中的单词
# -*- coding:utf-8 -*- import io import re class Counter: def __init__(self, path): """ :param path: 文件路径 """ self.mapping = dict() with io.open(path, encoding="utf-8") as f: data = f.read() words = [s.lower() for s in re.findall("\.
2021-05-01 16:47:12 2577
转载 Python 实现BFS
Breadth First Search in Pythongraph = { 'A' : ['B','C'], 'B' : ['D', 'E'], 'C' : ['F'], 'D' : [], 'E' : ['F'], 'F' : []}visited = [] # List to keep track of visited nodes.queue = [] #Initialize a queuedef bfs(visited, graph, node
2021-05-01 16:44:34 301
转载 Python yield Keyword
link:https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-doTo understand whatyielddoes, you must understand whatgeneratorsare. And before you can understand generators, you must understanditerables.IterablesWhen you create a ...
2021-04-23 15:57:41 81
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人