This file contains 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
#include <cstdint> | |
#include <cassert> | |
#include <vector> | |
static constexpr int INF = 1'000'000'007; | |
using i32 = std::int32_t; | |
using namespace std; | |
i32 LowerBound(const vector<i32>& nums, const i32 key) { |
This file contains 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
package main | |
const INF = int(1e9 + 7) | |
func LowerBound(nums []int, key int) int { | |
lo := 0 | |
hi := len(nums) - 1 | |
ans := -1 | |
for lo <= hi { | |
mi := lo + (hi-lo)/2 |
This file contains 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
INF = 10**9+7 | |
def LowerBound(nums, key): | |
lo = 0 | |
hi = len(nums) - 1 | |
ans = -1 | |
while lo <= hi: | |
mi = lo + (hi - lo) // 2 | |
if nums[mi] < key: |
This file contains 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
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 |
This file contains 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
#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}; |
This file contains 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
package main | |
import ( | |
"fmt" | |
) | |
type Node struct { | |
Data interface{} | |
Prev *Node | |
Next *Node |
This file contains 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
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 |
This file contains 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
#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>; |
This file contains 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
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]): |
This file contains 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
package main | |
import ( | |
"fmt" | |
) | |
type Node[KeyT comparable, ValueT any] struct { | |
key KeyT | |
value ValueT | |
prev *Node[KeyT, ValueT] |