Skip to content

Instantly share code, notes, and snippets.

@SeanHwangG
SeanHwangG / set.go
Created April 8, 2022 01:57 — forked from bgadrian/set.go
How to implement a simple set data structure in golang
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
}
// 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.
@SeanHwangG
SeanHwangG / dockerfile
Last active January 25, 2021 13:25 — forked from strezh/GStreamer-1.0 some strings.sh
GStreamer-1.0 personal cheat sheet
$ 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}
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
import time
import threading
pencil = threading.Lock()
items_on_notepad = 0
def shopper():
global items_on_notepad
name = threading.current_thread().getName()
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
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
# 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
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))
class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
return [sum(m < n for m in nums) for n in nums]