Once more unto the uhbis, dear friends!


Best Way to Check if a Number Contains Another Number

Need to find out if a number contains another number? And you want better performance than converting to a string and then looping through that to find the key number? Well you’ve come to the right place! Using a combination of the modulo operator and division it’s possible to pull the number apart one digit at a time until it reaches 0. Implementation Using a Loop Python Go JavaScript C++ Java def checkNumberIfContainsKey(number, key): while number > 0: if number % 10 == key: return True number = number // 10 return False package main import "fmt" func checkNumberIfContainsKey(number, key int) bool { for number > 0 { if number%10 == key { return true } number = number / 10 } return false } func main() { fmt. Read more...

Two Sum

Given an array of unsorted numbers nums and an integer target, find two integers in the array that sum to the target and return their indices. There are three ways that I know of to solve this problem. Below you’ll find a description of each with some brief code examples. I would like to encourage you to try to implement your own solution first before scrolling down. Solution 1: Brute Force The first way, which is the brute force method, is to use nested loops. Read more...