fix(posts): fetch daily from files
This commit is contained in:
parent
3d2ee97afe
commit
2bcc3f4675
9 changed files with 691 additions and 0 deletions
18
public/code/algorithms/leetcode-daily/msl-naive.py
Normal file
18
public/code/algorithms/leetcode-daily/msl-naive.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def minimumSubarrayLength(self, nums, k):
|
||||
# provide a sentinel for "no window found"
|
||||
ans = sys.maxsize
|
||||
window = deque()
|
||||
l = 0
|
||||
|
||||
# expand the window by default
|
||||
for r in range(len(nums)):
|
||||
# consider `nums[r]`
|
||||
window.append(nums[r])
|
||||
# shrink window while valid
|
||||
while l <= r and reduce(operator.or_, window) >= k:
|
||||
ans = min(ans, r - l + 1)
|
||||
window.popleft()
|
||||
l += 1
|
||||
|
||||
# normalize to -1 as requested
|
||||
return -1 if ans == sys.maxsize else ans
|
||||
Loading…
Add table
Add a link
Reference in a new issue