小编Ali*_*ice的帖子

详尽地获得三个字母的所有可能组合

我正在研究leetcode问题“ wordLadder”

给定两个单词(beginWordendWord),以及字典的单词列表,找到从beginWordendWord的最短转换序列的长度,例如:

  1. 一次只能更改一个字母。
  2. 每个转换的单词都必须存在于单词列表中。需要注意的是beginWord不是变换词。

注意:

  • 如果没有这样的转换序列,则返回0。
  • 所有单词的长度相同。
  • 所有单词仅包含小写字母字符。
  • 您可以假设单词列表中没有重复项。
  • 您可以假设beginWordendWord为非空并且不相同。

范例1:

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.
Run Code Online (Sandbox Code Playgroud)

范例2:

Input:
beginWord = "hit"
endWord = "cog"
wordList = ["hot","dot","dog","lot","log"]

Output: 0

Explanation: The endWord "cog" is not in wordList, …
Run Code Online (Sandbox Code Playgroud)

python

7
推荐指数
1
解决办法
137
查看次数

pip 安装 dbus-python 失败

我计划安装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)

python-3.x

6
推荐指数
2
解决办法
2万
查看次数

桶排序以查找附近的几乎重复项

我正在研究包含重复III的问题 -LeetCode

给定一个整数数组,找出是否有两个不同的索引Ĵ阵列中,使得绝对之间差NUMS [I]NUMS [j]的**为至多和**绝对之间差j最多为k

范例1:

Input: nums = [1,2,3,1], k = 3, t = 0
Output: true
Run Code Online (Sandbox Code Playgroud)

范例2:

Input: nums = [1,0,1,1], k = 1, t = 2
Output: true
Run Code Online (Sandbox Code Playgroud)

范例3:

Input: nums = [1,5,9,1,5,9], k = 2, t = 3
Output: false
Run Code Online (Sandbox Code Playgroud)

阅读讨论区中的存储桶排序解决方案

class Solution2:
    def containsNearbyAlmostDuplicate(self, nums, k, t):
        if t < 0: return False
        lookup = …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
159
查看次数

最大连续数

我正在练习两指针技术来解决最大连续数 - LeetCode

给定一个二进制数组,找出该数组中连续 1 的最大数量。

示例1:

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.
Run Code Online (Sandbox Code Playgroud)

笔记:

  • 输入数组将仅包含01
  • 输入数组的长度为正整数且不会超过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)

python algorithm

4
推荐指数
1
解决办法
6203
查看次数

orgmode 中的注释行

使用注释行查阅组织文档:

组织手册:评论行

12.6 注释行

以零个或多个空格字符开头、后跟一个“#”和一个空格的行被视为注释,因此不会导出。

同样,被#+BEGIN_COMMENT ... 包围的区域 #+END_COMMENT 不会被导出。

最后,在条目开头的“COMMENT”关键字,但在任何其他关键字或优先级 cookie 之后,注释掉整个子树。在这种情况下,不会导出子树,也不会执行其中的任何代码块129。下面的命令有助于更改标题的评论状态。

C-c ;

切换条目开头的“COMMENT”关键字。

#+BEGIN_COMMENT … #+END_COMMEN 工作正常。

在此处输入图片说明

然而,

以零个或多个空格字符开头、后跟一个“#”和一个空格的行被视为注释,因此不会导出。

在此处输入图片说明

我误解了那个说法吗?

emacs comments org-mode

4
推荐指数
1
解决办法
829
查看次数

在 Typora 中显示数学符号

我阅读了leetcode的官方解决方案来反转整数

将以下内容复制到我的降价笔记后

在此处输入图片说明

但得到

在此处输入图片说明

我使用通常功能强大的typora。

为什么内容无法显示在网站上?

markdown

3
推荐指数
1
解决办法
2900
查看次数

为什么二进制文字中需要前导0,例如'0b10101000'?

我感到困惑的领导00b10101000:

它似乎不是一个标志符号.

In [1]: bin(168)
Out[1]: '0b10101000'

In [2]: int(bin(168), 2)
Out[2]: 168
Run Code Online (Sandbox Code Playgroud)

我认为它应该足够了,而且说肯定会更简洁b10101000.

为什么0需要领先?

python

1
推荐指数
1
解决办法
87
查看次数

缩短测试`if find_num_3!= None和find_num_3!= i和find_num_3!= j的长时间条件:

我进行了这样的连锁条件测试:

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)

如何将长链转变为紧凑的短结构。

python

1
推荐指数
1
解决办法
62
查看次数

运行等待功能的 Jupyter 笔记本

在Jupyter notebook 上学习协程和任务后

运行以下代码

import asyncio
async def main():
    print('learn')
    await asyncio.sleep(1)
    print('Jupyter')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是,它在 Ipython 上正常工作

在此处输入图片说明

python

1
推荐指数
1
解决办法
912
查看次数

sub() 缺少 1 个必需的位置参数:'string'

我用 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\n
Run Code Online (Sandbox Code Playgroud)\n\n

运行但是报错:

\n\n
 TypeError: sub() missing 1 required positional argument: \xe2\x80\x99string\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n\n

既然没有缺少任何参数,那么问题是什么?

\n

python regex

-4
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×7

algorithm ×1

comments ×1

emacs ×1

markdown ×1

org-mode ×1

python-3.x ×1

regex ×1