K

@kenbitanga

JS - Async/Await

NodeJS
2 years ago
const work = () => { return new Promise(resolve => { setTimeout(() => resolve('doing work'), 3000); }) }; const doWork = async () => { console.log(await work()); };

JS - Promise

NodeJS
2 years ago
const work = () => { return new Promise(resolve => { setTimeout(() => resolve('doing work'), 3000); }) }; console.log('before'); work().then(e => { console.log(e);

JS - Two Sum - Using JS Object & Map Object

NodeJS
2 years ago
function twoSumObj(nums, target) { const obj = {} for (const i in nums) { let diff = target - nums[i] if (diff in obj) { return [+obj[diff], +i] } obj[nums[i]] = i } return []

Golang - Stack Implementation Using a Slice

Go
2 years ago
package main import "fmt" type Stack struct { data []string } func (s *Stack) Push(x string) { s.data = append(s.data, x) }

Golang - Two Sum

Go
2 years ago
package main import "fmt" func twoSum(nums []int, target int) []int { memo := map[int]int{} for i := 0; i < len(nums); i++ { num := nums[i] diff := target - num if _, ok := memo[diff]; ok {

Kotlin - Two Sum

Kotlin
2 years ago
class Solution { fun twoSum(nums: IntArray, target: Int): IntArray { val prevMap = hashMapOf<Int, Int>() for ((i, num) in nums.withIndex()) { val diff = target - num if (prevMap.containsKey(diff))

C++ - Two Sum - Leetcode 1 - Unordered Map - Class - Static

C++
2 years ago
#include <iostream> #include <vector> #include <unordered_map> class Solution { public: static std::vector<int> twoSum(const std::vector<int>& nums, const int target) { std::unordered_map<int, int> map {};

C++ - Two Sum - Leetcode 1 - Unordered Map - Class - Operator<< Overloaded

C++
2 years ago
#include <iostream> #include <vector> #include <unordered_map> class Solution { std::vector<int> result {}; public:

Golang - Two Sum - Leetcode 1 - Slice, Range, Map

Go
2 years ago
package main import "fmt" func twoSum(nums []int, targ int) []int { prevMap := make(map[int]int) for i, v := range nums { diff := targ - v // same as: if (prevMap.containsKey(diff)) {}

Kotlin - Two Sum - Leetcode 1 - HashMap

Kotlin
2 years ago
class Solution { fun twoSum(nums: IntArray, target: Int): IntArray { val prevMap: HashMap<Int, Int> = HashMap() for (i in nums.indices) { val num = nums[i] val diff = target - num if (prevMap.c

C++ - Two Sum - Leetcode 1 - Unordered Map - Class - Operator<< Overloaded

C++
2 years ago
#include <iostream> #include <vector> #include <unordered_map> class Solution { std::vector<int> result {}; public: void twoSum(std::vector<int>& nums, int target) { std::unordered_map<int, int> map {}; result = {};

C++: Overloading the << operator

C++
2 years ago
#include <iostream> using namespace std; class Date { int mo, da, yr; public: Date(int m, int d, int y) { mo = m; da = d; yr = y;

C#: Dictionary Methods

C#
2 years ago
using System; using System.Collections.Generic; namespace MyCompiler { class Program { public static void Main(string[] args) { var map = new Dictionary<int, int>(); // add entry to dictionary; throw

C#: Array to String

C#
2 years ago
using System; namespace MyCompiler { class Program { public static void Main(string[] args) { int[] nums = {1,2,3}; // use string.Join(separator, array) Console.WriteLine("[" + string.Joi

PHP - Two Sum - Leetcode 1 - Associative Array

PHP
2 years ago
<?php class Solution { /** * @param Integer[] $nums * @param Integer $target * @return Integer[] */ function twoSum($nums, $target) {

C++ - Two Sum - Leetcode 1 - Unordered Map

C++
2 years ago
#include <iostream> #include <vector> #include <unordered_map> std::vector<int> twoSum(std::vector<int>& nums, int target) { std::unordered_map<int, int> map {}; std::vector<int> output {}; for (int i = 0; i < nums.size(); i++) {

Java - Two Sum - Leetcode 1 - HashMap

Java
2 years ago
import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { private static int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); f

JS - Two Sum - Leetcode 1 - Map

NodeJS
2 years ago
function twoSum(nums, target) { const prevMap = new Map(); for (let i=0; i<nums.length; i++) { let diff = target - nums[i]; if (prevMap.has(diff)) { return [prevMap.get(diff), i]; } prevMap.set(num

C# - Two Sum - Leetcode 1 - Dictionary

C#
2 years ago
using System; using System.Collections.Generic; namespace MyCompiler { class Program { public static void Main(string[] args) { var sol = new Solution(); int[] nums = new int[] {1,2,3,4,5};

Python: Two Sum - Leetcode 1 - HashMap

Python
2 years ago
class Solution: def twoSum(self, nums, target): prevMap = {} # val : index for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i]