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
| package main | |
| import "fmt" | |
| type Set[T comparable] struct { | |
| items map[T]struct{} | |
| } | |
| func NewSet[T comparable]() *Set[T] { | |
| return &Set[T]{ |
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
| #include <iostream> | |
| #include <stdexcept> | |
| #include <type_traits> | |
| #include <unordered_map> | |
| #include <unordered_set> | |
| #include <optional> | |
| #include <cassert> | |
| using namespace std; |
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
| version: '3' | |
| services: | |
| postgres: | |
| image: 'postgres:14.5' | |
| container_name: "postgres_isolation" | |
| restart: always | |
| environment: | |
| - POSTGRES_DB=isolation_levels |
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
| [Connection] | |
| brew install pgcli | |
| pgcli -h localhost -p 5432 -U postgres isolation_levels # password postgres | |
| [Preparation] | |
| DROP TABLE IF EXISTS accounts; | |
| CREATE TABLE accounts ( | |
| id SERIAL PRIMARY KEY, |
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
| const ( | |
| INF = int(1e9) | |
| ) | |
| func maxProfit(prices []int) int { | |
| cache := createCache(len(prices), -1) | |
| return run(0, 0, prices, cache) | |
| } | |
| func createCache[T any](N int, val T) [][]T { |
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
| const ( | |
| INF = int(1e9) | |
| ) | |
| var ( | |
| cache [100001][2]int | |
| ) | |
| func maxProfit(nums []int) int { | |
| initCache(len(nums), -1) |
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
| const ( | |
| INF = int(1e9) | |
| ) | |
| var ( | |
| cache [100001][2]int | |
| nums [100001]int | |
| N int | |
| ) |
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
| static int INF = 1e9+7; | |
| static int N = 0; | |
| static vector<int> nums; | |
| static int cache[100001][2]; | |
| static void init(vector<int>& prices) { | |
| N = size(prices); | |
| nums.resize(N); | |
| for (int i = 0; i < N; ++i) { | |
| nums[i] = prices[i]; |
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
| static int INF = 1e9+7; | |
| static int cache[100001][2]; | |
| static int run(int idx, int taken, vector<int>& nums) { | |
| const int N = size(nums); | |
| if (idx == N and taken == 1) return -INF; | |
| if (idx == N) return 0; | |
| if (cache[idx][taken] != -1) return cache[idx][taken]; | |
| if (taken) return cache[idx][taken] = max( | |
| run(idx + 1, 1, nums), |
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 maxProfit(self, nums: List[int]) -> int: | |
| return sol8(nums) | |
| def sol1(nums): | |
| N = len(nums) | |
| INF = 10**10 | |
| @cache | |
| def run(idx, taken): |