String

Minimum Cost to Merge Stones

Valid Parentheses LeetCode Solution | Easy Approach

Valid Parentheses | Given a string s containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example 1: Input: s = “()” Output: true Example 2: Input: s = …

Valid Parentheses LeetCode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Letter Combinations of a Phone LeetCode Solution | Easy Approach

Letter Combinations of a Phone | Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits …

Letter Combinations of a Phone LeetCode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Longest Common Prefix LeetCode Solution | Easy Approach

Longest Common Prefix | Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: strs = [“flower”,”flow”,”flight”] Output: “fl” Example 2: Input: strs = [“dog”,”racecar”,”car”] Output: “” Explanation: There is no common prefix among the input strings. …

Longest Common Prefix LeetCode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Roman to Integer LeetCode Solution | Easy Approach

Roman to Integer | Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + …

Roman to Integer LeetCode Solution | Easy Approach Read More »

Regular Expression Matching Leetcode Solution | Easy Approach

Regular Expression Matching Leetcode Solution | Given an input string s and a pattern p, implement regular expression matching with support for ‘.’ and ‘*’ where: ‘.’ Matches any single character.​​​​ ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). Example 1: Input: s = “aa”, p = “a” Output: false Explanation: “a” does not match …

Regular Expression Matching Leetcode Solution | Easy Approach Read More »

String to Integer (atoi) Leetcode Solution | Easy Approach

Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++’s atoi function). The algorithm for myAtoi(string s) is as follows: Read in and ignore any leading whitespace. Check if the next character (if not already at the end of the string) is ‘-‘ or ‘+’. Read this character in if it is either. This determines if the …

String to Integer (atoi) Leetcode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Integer to Roman Leetcode Solution | Easy Approach

Integer to Roman | Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + …

Integer to Roman Leetcode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Longest Palindromic Substring LeetCode Solution | Easy Approach

Longest Palindromic Substring | Given a string s, return the longest palindromic substring in s. Example 1: Input: s = “babad” Output: “bab” Explanation: “aba” is also a valid answer. Example 2: Input: s = “cbbd” Output: “bb” Constraints: 1 <= s.length <= 1000 s consist of only digits and English letters. Solutions 1. Naive Approach âś…Time: O(n*n)âś…Space: O(n) C++ Java Python …

Longest Palindromic Substring LeetCode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

Longest Substring Without Repeating Characters Leetcode Solution

Longest Substring Without Repeating Characters | Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = “abcabcbb” Output: 3 Explanation: The answer is “abc”, with the length of 3. Example 2: Input: s = “bbbbb” Output: 1 Explanation: The answer is “b”, with the length of 1. Example 3: …

Longest Substring Without Repeating Characters Leetcode Solution Read More »

x