https://leetcode.com/problems/word-search-ii/
先clone
Word Search的写法,再稍作更动,并加速一下。
Hard
@JohnTing
加速法: 加上filter
如果word当中的character不在board里,就不用找那个word了!
https://leetcode.com/problems/bitwise-and-of-numbers-range/
Ex: [5,8]
101 <- len = 3
110
& 111
1000 <- len = 4
-------
0000
class Solution:
def rangeBitwiseAnd(self, left: int, right: int) -> int:
if len(bin(left)) != len(bin(right)):
return 0
for i in range(left+1,right+1):
left = left & i
return left
Ex: [5,7]
idx 210
-------
101
110
& 111
-------
100
-
找出Out非1的位置,以[5,7]为例,则为index是2的情况,
index 2左边(包含2)保留
,index 2右边舍弃
。
以右移方式(/2)来找Out非1的位置,
右移直到m,n相同就停止,右移同时使用counter记录移了几次
PS: 右移 (>>1)
再由m左移counter(m/n
<<counter)即所得。
PS: m/n == m或n
class Solution:
def rangeBitwiseAnd(self, left: int, right: int) -> int:
'''
>> -> /2
<< -> *2
421
------
5: 101
6: 110
7: 111
-------
100
OXX O: the same X: diffirent
可移掉右边清为空留下左边
移掉右边 -> 最後成00
留下左边 -> 不动
op1: >> also means drop right bit
do (>> 1) + counter until m == n
op2: << counter
'''
cnt = 0
while left!=right:
left >>= 1
right >>= 1
cnt+=1
return right << cnt
Medium
>>: Day 29 Realm的练习-使用者注册系统(3/3)
今天在网路上看到这张照片,非常的有共鸣,因为人生就是 既便奋战到底,还是有会输得一塌糊涂的一天 但...
什麽是资料库中的交易控制呢,即是当A帐户转帐给B帐户时,B帐户却因为系统问题无法顺利入帐,但A帐户已...
之前的文章介绍了如何在 OpenShift 透过 Prometheus,AlertManager 跟...
上一篇提到,要深入了解需求,需要大量的沟通,对应到 DDD 中非常重要的一环——与领域专家一同开会。...
Bootstrap 是全球最流行的前端开发工具,可以快速设计及自定义响应式网站。而 WordPres...