How to solve LeetCode problem

LeetCode #28 Find the Index of the First Occurrence in a String

Javascript – LeetCode problem #28 Find the Index of the First Occurrence in a String In this problem, we need to create a method that detects if a given string (needle) occurs in another string (haystack) and return the index. Read the problem on LeetCode. Going letter by letter? It’s pretty obvious that we need some form of loop to compare both strings with each other. One option would be to evaluate letter by letter.…

How to solve LeetCode problem

How to solve LeetCode problem #9 Palindrome

Javascript – Leetcode problem #9 Palindrome In this problem, we need to create a message that evaluates if a given integer is a palindrome (reads the same way from left>right and right>left) and return true or false. Read the full problem on LeetCode. Pattern – How to detect a palindrome A palindrome is a string that reads the same from left to right or right to left, i.e. “Otto”, “121”. To detect whether a given…

How to solve LeetCode problem

How to solve LeetCode problem #12 Integer to Roman

Javascript – LeetCode problem #12 Integer to Roman In this problem, we need to create a method that translates an Integer (1<=n<=3999) to a Roman numeral. Read the full problem on LeetCode. Pattern – Deconstruct the Integer The key to solving this problem is understanding the construction pattern of Roman numerals: In summary, we need to look at each digit of the Integer and its “weigth” (thousands, hundres, etc.), then determine the correct Roman numeral…

How to solve LeetCode problem

How to solve LeetCode problem #13: Roman to Integer

Javascript – LeetCode problem #13 Roman to Integer In this problem, we need to create a method for converting Roman numerals into Integers (i.e. MMXXIV => 2024; III => 3; IX => 9; …). Read the full problem here. Pattern – Deconstruct the Roman numeral The key to solving this problem is understanding the construction pattern of Roman numerals: In summary, we need to look at each letter of the Roman numeral and compare it…