This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Set struct { | |
list map[int]struct{} //empty structs occupy 0 memory | |
} | |
func (s *Set) Has(v int) bool { | |
_, ok := s.list[v] | |
return ok | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++ includes used for precompiling -*- C++ -*- | |
// Copyright (C) 2003-2013 Free Software Foundation, Inc. | |
// | |
// This file is part of the GNU ISO C++ Library. This library is free | |
// software; you can redistribute it and/or modify it under the | |
// terms of the GNU General Public License as published by the | |
// Free Software Foundation; either version 3, or (at your option) | |
// any later version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker run --network host \ # Container will use the host network stack. | |
-it \ # For interactive processes (like a bash) | |
--privileged=true -v /dev:/dev \ # Container will enable access to all devices on the host. | |
--env="DISPLAY" -v "$HOME/.Xauthority:/root/.Xauthority:rw" \ # enable to proxy GUI to host. | |
--env QT_X11_NO_MITSHM=1 \ | |
--security-opt apparmor:unconfined \ | |
-v /home/user/work:/media/work \ # {host_path}:{container_path} mount a host directory to container. | |
gstreamer:1.14.1 # gstreamer:1.14.1 : {ImageName}:{TAG} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def __init__(self, head): | |
self.head = head | |
def getRandom(self): | |
result, node, index = self.head, self.head.next, 1 | |
while node: | |
if random.randint(0, index) is 0: | |
result = node |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import threading | |
pencil = threading.Lock() | |
items_on_notepad = 0 | |
def shopper(): | |
global items_on_notepad | |
name = threading.current_thread().getName() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def strongPasswordChecker(self, s): | |
missing_type = 3 | |
if any('a' <= c <= 'z' for c in s): missing_type -= 1 | |
if any('A' <= c <= 'Z' for c in s): missing_type -= 1 | |
if any(c.isdigit() for c in s): missing_type -= 1 | |
change = 0 | |
one = two = 0 | |
i = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def canJump(self, nums: List[int]) -> bool: | |
pos = 0 | |
for i, n in enumerate(nums): | |
if i <= pos: | |
pos = max(pos, i + n) | |
return len(nums) - 1 <= pos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, val=0, next=None): | |
# self.val = val | |
# self.next = next | |
class Solution: | |
def middleNode(self, head: ListNode) -> ListNode: | |
slow, fast = head, head | |
while fast and fast.next: | |
slow = slow.next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def largestDivisibleSubset(self, nums: List[int]) -> List[int]: | |
S = {-1: set()} | |
for x in sorted(nums): | |
S[x] = max((S[d] for d in S if x % d == 0), key=len) | {x} | |
return list(max(S.values(), key=len)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]: | |
return [sum(m < n for m in nums) for n in nums] |
NewerOlder