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 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) { |
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 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]; |
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
| # 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 |
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
| type Props = { | |
| names: string[]; | |
| } | |
| const UsersList = ({ names }: Props) => ( | |
| <div> | |
| <Fetch | |
| render={ | |
| <ul className="list"> | |
| {names.map((name:string) => ( | |
| <li>{name}</li> |
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
| type Props = { | |
| render: React.ReactNode; | |
| empty: React.ReactNode; | |
| isEmpty: boolean; | |
| } | |
| const Fetch = ({ render, empty, isEmpty }) => { | |
| if (isEmpty) { | |
| return <> { empty } </>; | |
| } |
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 Example = () => { | |
| const a = true; | |
| const b = false; | |
| const c = false; | |
| return ( | |
| { | |
| a ? ( | |
| { | |
| b ? ( |
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
| type Props = { | |
| names: string[]; | |
| } | |
| const UsersList = ({ names }: Props) => ( | |
| <div> | |
| { | |
| names.length > 0 ? ( | |
| <ul className="list"> | |
| {names.map((name:string) => ( |
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
| """ | |
| 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 |
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
| 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)) |
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 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)); |
NewerOlder