Skip to content

Instantly share code, notes, and snippets.

View yevmoroz's full-sized avatar
🏠
Working from home

Yevhenii Moroz yevmoroz

🏠
Working from home
View GitHub Profile
@yevmoroz
yevmoroz / docker-compose.yml
Created June 1, 2024 17:21
umbrel tailscale exit node docker compose setup
version: '3.7'
services:
web:
network_mode: host
image: >-
tailscale/tailscale:v1.66@sha256:cf8e97667e8be250caaed88694cec0befe11040bbd5a3de3b33086cc52ef4eb1
restart: on-failure
stop_grace_period: 1m
environment:
- TS_EXTRA_ARGS=--advertise-exit-mode --exit-node-allow-lan-access
@yevmoroz
yevmoroz / uniquepaths.js
Created April 16, 2024 15:47
leetcode unique paths mxn
/**
* @param {number} m
* @param {number} n
* @return {number}
*/
function uniquePaths(m, n) {
let arr = [];
for (let i = 0; i <=m; i++) {
arr.push(new Array(n + 1).fill(0));
}
@yevmoroz
yevmoroz / sortedArrayToBST.js
Created April 16, 2024 15:43
leetcode sorted array to bst
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {number[]} nums
@yevmoroz
yevmoroz / BST.js
Created April 16, 2024 15:40
leetcode binary tree search
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
function shortestPathBinaryMatrix(grid) {
const directions = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1],
[1, 1],
[1, -1],
[-1, 1],
[-1, -1],
@yevmoroz
yevmoroz / uncommonwords.js
Created April 16, 2024 13:17
leetcode uncommon words
function uncommonWords(s1, s2) {
const words1 = s1.split(' ');
const words2 = s2.split(' ');
const freq = new Map();
for (const word of words1) {
freq.set(word, (freq.get(word) || 0) + 1);
}
@yevmoroz
yevmoroz / longestprefix.js
Created April 16, 2024 00:39
leetcode longest prefix
/**
* @param {string[]} strs
* @return {string}
*/
function longestCommonPrefix(strs) {
if (strs.length === 0) {
return "";
}
let prefix = strs[0];
@yevmoroz
yevmoroz / twosum.js
Created April 16, 2024 00:36
leetcode sum of 2 from list
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
function twoSum(nums, target) {
let mp = new Map()
for (let i = 0; i < nums.length; i++) {
let diff = target - nums[i]
@yevmoroz
yevmoroz / frequentwords.js
Last active April 16, 2024 13:31
leetcode frequent words
function topKFrequentWords(words, k) {
const freq = new Map();
for (const word of words) {
if (!freq.has(word)) {
freq.set(word, 1);
} else {
freq.set(word, freq.get(word) + 1);
}
}
@yevmoroz
yevmoroz / randset.js
Created April 16, 2024 00:11
leetcode randset
class RandomizedSet {
constructor() {
this.set = new Map();
this.array = [];
}
insert(val) {
if (this.set.has(val)) {
return false;
}