Skip to content

Instantly share code, notes, and snippets.

View idfumg's full-sized avatar

Artem Pushkin idfumg

View GitHub Profile
package main
import "fmt"
type Set[T comparable] struct {
items map[T]struct{}
}
func NewSet[T comparable]() *Set[T] {
return &Set[T]{
from typing import TypeAlias, Tuple, Hashable, TypeVar, Generic
FrequencyT: TypeAlias = int
ValueT = TypeVar("ValueT")
ValueFrequencyT: TypeAlias = tuple[ValueT, FrequencyT]
KeyT = TypeVar("KeyT", bound=Hashable)
KeysT: TypeAlias = set[KeyT]
#include <iostream>
#include <unordered_map>
#include <list>
#include <optional>
#include <cassert>
using namespace std;
template <class T>
concept Hashable = requires(T param) { std::hash<T>()(param); };
package main
import (
"fmt"
)
type Node[KeyT comparable, ValueT any] struct {
key KeyT
value ValueT
prev *Node[KeyT, ValueT]
from typing import TypeVar, Generic, Optional, Hashable, TypeAlias
from icecream import ic # type: ignore
KeyT = TypeVar("KeyT", bound=Hashable)
ValueT = TypeVar("ValueT")
class Node(Generic[KeyT, ValueT]):
def __init__(self, key: Optional[KeyT], value: Optional[ValueT]):
#include <initializer_list>
#include <iostream>
#include <memory>
#include <cassert>
template<class T>
struct Node {
using LPtr = std::weak_ptr<Node>;
using RPtr = std::shared_ptr<Node>;
from typing import Any
from icecream import ic # type: ignore # pip install icecream
class Node:
def __init__(self, data: Any):
self.data: Any = data
self.prev: Node
self.next: Node
package main
import (
"fmt"
)
type Node struct {
Data interface{}
Prev *Node
Next *Node
#include <initializer_list>
#include <iostream>
#include <memory>
// -fsanitize=address -stdlib=libc++ -g -O0 -pedantic -fstack-protector -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_DEBUG -fsanitize=undefined -Wall -Werror -std=c++20
template<class T>
struct Node {
T data {};
std::shared_ptr<Node> prev = {nullptr};
from icecream import ic # type: ignore # pip install icecream
def GetSum(n):
if n == 0: return 0
return n + GetSum(n - 1)
def GetLength(nums, n):
if n == -1: return 0