Leetcode Solutions

Leetcode solutions MLP Feature Image

[Solved] Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number.

Question Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28 … Example 1: Input: columnTitle = “A” Output: 1 Example 2: Input: columnTitle = “AB” Output: […]

[Solved] Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n – 1) * (n – 2) * … * 3 * 2 * 1.

Question Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n – 1) * (n – 2) * … * 3 * 2 * 1. Example 1: Input: n = 3 Output: 0 Explanation: 3! = 6, no trailing zero. Example 2: Input: n = 5 Output: 1 Explanation: 5!

[Solved] Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n – 1) * (n – 2) * … * 3 * 2 * 1. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length.

Question Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. The tests are generated such that there is exactly one solution. You may

[Solved] Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

Question Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 Constraints: n == nums.length 1 <= n

[Solved] Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given two version numbers, version1 and version2, compare them. Version numbers consist of one or more revisions joined by a dot ‘.’. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character.

Question Given two version numbers, version1 and version2, compare them. Version numbers consist of one or more revisions joined by a dot ‘.’. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Revisions are 0-indexed from left to right, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example 2.5.33 and 0.1 are valid version

[Solved] Given two version numbers, version1 and version2, compare them. Version numbers consist of one or more revisions joined by a dot ‘.’. Each revision consists of digits and may contain leading zeros. Every revision contains at least one character. Read More »

Leetcode solutions MLP Feature Image

[Solved] Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Question Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: MinStack() initializes the stack object. void push(int val) pushes the element val onto the stack. void pop() removes the element on the top of the stack. int top() gets the top element of the stack. int getMin() retrieves the minimum element in the

[Solved] Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Read More »

Leetcode solutions MLP Feature Image

[Solved] You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln – 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln – 1 → L2 → Ln – 2 → …

Question You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln – 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln – 1 → L2 → Ln – 2 → … You may

[Solved] You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln – 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln – 1 → L2 → Ln – 2 → … Read More »

Leetcode solutions MLP Feature Image

[Solved] Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null.

Question Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is

[Solved] Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given head, the head of a linked list, determine if the linked list has a cycle in it.

Question Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail’s next pointer is connected

[Solved] Given head, the head of a linked list, determine if the linked list has a cycle in it. Read More »

Leetcode solutions MLP Feature Image

[Solved] Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space.

Question Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1: Input: nums = [2,2,3,2] Output: 3 Example 2: Input: nums = [0,1,0,1,0,1,99] Output: 99 Constraints: 1 <= nums.length <= 3 *

[Solved] Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. Read More »

Scroll to Top