我正在研究leetcode问题“ wordLadder”
给定两个单词(beginWord和endWord),以及字典的单词列表,找到从beginWord到endWord的最短转换序列的长度,例如:
- 一次只能更改一个字母。
- 每个转换的单词都必须存在于单词列表中。需要注意的是beginWord是不是变换词。
注意:
- 如果没有这样的转换序列,则返回0。
- 所有单词的长度相同。
- 所有单词仅包含小写字母字符。
- 您可以假设单词列表中没有重复项。
- 您可以假设beginWord和endWord为非空并且不相同。
范例1:
Run Code Online (Sandbox Code Playgroud)Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] Output: 5 Explanation: As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", return its length 5.范例2:
Run Code Online (Sandbox Code Playgroud)Input: beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log"] Output: 0 Explanation: The endWord "cog" is not in wordList, …
我计划安装dbus-python:
$ pip --version; python --version
pip 19.0.3 from /home/me/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
Python 3.7.3
Run Code Online (Sandbox Code Playgroud)
该平台:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.10
Release: 18.10
Codename: cosmic
Run Code Online (Sandbox Code Playgroud)
当我运行时pip install dbus-python,它报告以下错误:
checking for DBUS... no
configure: error: in `/tmp/pip-install-hr9djbwg/dbus-python/build/temp.linux-x86_64-3.7':
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config. …Run Code Online (Sandbox Code Playgroud) 给定一个整数数组,找出是否有两个不同的索引我和Ĵ阵列中,使得绝对之间差NUMS [I]和NUMS [j]的**为至多吨和**绝对之间差我和j最多为k。
范例1:
Run Code Online (Sandbox Code Playgroud)Input: nums = [1,2,3,1], k = 3, t = 0 Output: true范例2:
Run Code Online (Sandbox Code Playgroud)Input: nums = [1,0,1,1], k = 1, t = 2 Output: true范例3:
Run Code Online (Sandbox Code Playgroud)Input: nums = [1,5,9,1,5,9], k = 2, t = 3 Output: false
阅读讨论区中的存储桶排序解决方案
class Solution2:
def containsNearbyAlmostDuplicate(self, nums, k, t):
if t < 0: return False
lookup = …Run Code Online (Sandbox Code Playgroud) 我正在练习两指针技术来解决最大连续数 - LeetCode
给定一个二进制数组,找出该数组中连续 1 的最大数量。
示例1:
Run Code Online (Sandbox Code Playgroud)Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.笔记:
- 输入数组将仅包含
0和1。- 输入数组的长度为正整数且不会超过10,000
该解决方案使用Kadane算法
class Solution:
def findMaxConsecutiveOnes(self, nums: "List[int]") -> int:
loc_max = glo_max = 0
for i in range(len(nums)):
if nums[i] == 1:
loc_max += 1
elif nums[i] != 1:
glo_max = max(glo_max, loc_max)
loc_max = 0
#in case of the …Run Code Online (Sandbox Code Playgroud) 使用注释行查阅组织文档:
12.6 注释行
以零个或多个空格字符开头、后跟一个“#”和一个空格的行被视为注释,因此不会导出。
同样,被
#+BEGIN_COMMENT... 包围的区域#+END_COMMENT不会被导出。最后,在条目开头的“COMMENT”关键字,但在任何其他关键字或优先级 cookie 之后,注释掉整个子树。在这种情况下,不会导出子树,也不会执行其中的任何代码块129。下面的命令有助于更改标题的评论状态。
C-c ;
切换条目开头的“COMMENT”关键字。
#+BEGIN_COMMENT … #+END_COMMEN 工作正常。
然而,
以零个或多个空格字符开头、后跟一个“#”和一个空格的行被视为注释,因此不会导出。
我误解了那个说法吗?
我感到困惑的领导0在0b10101000:
它似乎不是一个标志符号.
In [1]: bin(168)
Out[1]: '0b10101000'
In [2]: int(bin(168), 2)
Out[2]: 168
Run Code Online (Sandbox Code Playgroud)
我认为它应该足够了,而且说肯定会更简洁b10101000.
为什么0需要领先?
我进行了这样的连锁条件测试:
if find_num_3 != None and find_num_3 != i and find_num_3 != j: #don't reproduce itself
Run Code Online (Sandbox Code Playgroud)
在代码中:
for i in range(len(nums)):
num_1= nums[i]
sub_target = target - num_1
logging.debug(f"level_1_lookup: {lookup}")
for j in range(i+1, len(nums)):
num_2 = nums[j] #
num_3 = sub_target - num_2
find_num_3 = lookup.get(num_3) #
if find_num_3 != None and find_num_3 != i and find_num_3 != j: #don't reproduce itself
result = [num_1, num_2, num_3]
triplets.append(result)
logging.debug(f"lookup: {lookup} sub_nums: {nums[j:]} \nresult: {result}")
logging.info(f"\ttriplets: {triplets}\n\n\n\n")
return triplets
Run Code Online (Sandbox Code Playgroud)
如何将长链转变为紧凑的短结构。
在Jupyter notebook 上学习协程和任务后,
运行以下代码
import asyncio
async def main():
print('learn')
await asyncio.sleep(1)
print('Jupyter')
Run Code Online (Sandbox Code Playgroud)
但是,它在 Ipython 上正常工作
我用 re.verbose 写了这样一个正则表达式
\n\n#+begin_src ipython :session flask :results output\nimport re\n\ndef clearup(path):\n fp = open(path, \'r+\')\n text = fp.read()\n text = re.sub(r\'\'\'.*PROPERTIES:.*\\n\n (?:.*\\n)* # multiple lines in the middle\n .*:END: \'\'\',text, flags=re.VERBOSE)\n fp.seek(0)\n fp.write(text)\n fp.close()\n\nclearup("01.foreword.org")\n#+end_src\nRun Code Online (Sandbox Code Playgroud)\n\n运行但是报错:
\n\n TypeError: sub() missing 1 required positional argument: \xe2\x80\x99string\xe2\x80\x99\nRun Code Online (Sandbox Code Playgroud)\n\n既然没有缺少任何参数,那么问题是什么?
\n