Skip to content

Instantly share code, notes, and snippets.

package com.algorithms.huy;
import java.util.HashMap;
import java.util.Map;
// https://leetcode.com/problems/contains-duplicate-iii/submissions/
public class ContainsDuplicate3 {
private static boolean condition(int a, int b, int t) {
if (a == b) {
class ContainsDuplicateThree {
// https://leetcode.com/problems/contains-duplicate-iii/
static boolean algorithm(int[] nums, int k, int t) {
SortedSet<Integer> set = new TreeSet<>();
for(int i = 0 ; i < nums.length; i++){
int[] solution = getBound(nums[i], t);
int leftBound = solution[0];
int rightBound = solution[1];
# https://leetcode.com/problems/diagonal-traverse
def solution(matrix):
N = len(matrix)
if N == 0:
return []
M = len(matrix[0])
solution = []
d = 1 # Initially up.
row = 0
col = 0
type Props = {
names: string[];
}
const UsersList = ({ names }: Props) => (
<div>
<Fetch
render={
<ul className="list">
{names.map((name:string) => (
<li>{name}</li>
type Props = {
render: React.ReactNode;
empty: React.ReactNode;
isEmpty: boolean;
}
const Fetch = ({ render, empty, isEmpty }) => {
if (isEmpty) {
return <> { empty } </>;
}
const Example = () => {
const a = true;
const b = false;
const c = false;
return (
{
a ? (
{
b ? (
type Props = {
names: string[];
}
const UsersList = ({ names }: Props) => (
<div>
{
names.length > 0 ? (
<ul className="list">
{names.map((name:string) => (
"""
Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1?
(eg given s1 = ABCD and s2 = CDAB, return true, given s1 = ABCD, and s2 = ACBD , return false)
"""
def isRotated(s1, s2):
if len(s1) != len(s2):
return False
S = s1 + s1
@huyvoo
huyvoo / updateMatrix.py
Created October 7, 2020 07:48
updateMatrix.py
def getNeighbors(row, col, rows, cols):
lst = []
if row + 1 < rows:
lst.append((row + 1, col))
if row - 1 >= 0:
lst.append((row - 1, col))
if col + 1 < cols:
lst.append((row, col + 1))
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
let arr = [1, 2, 3];
const byTwo = (arr) => arr.map(r => r * 2);
const all = (arr) => arr.reduce((v, f) => v + f);
console.log(pipe(byTwo, all)(arr));