title stringlengths 1 100 | titleSlug stringlengths 3 77 | Java int64 0 1 | Python3 int64 1 1 | content stringlengths 28 44.4k | voteCount int64 0 3.67k | question_content stringlengths 65 5k | question_hints stringclasses 970
values |
|---|---|---|---|---|---|---|---|
[VIDEO] Step-by-Step Visualization - Checking for Overflow | reverse-integer | 0 | 1 | ERROR: type should be string, got "https://youtu.be/YCxDTkWqcxw\\n\\nStep 1: Extract the digit in the ones place of `x` by using the modulo operator and store it in `digit`\\n\\nStep 2: Add that digit to `reverse` as the rightmost digit\\n\\nStep 3: Remove the ones digit from `x` and continue until `x` equals 0.\\n\\nIn Python, the modulo operator works slightly differently than other languages (such as Java or C) when it comes to negative numbers. Basically, you will get weird results if you try to do [positive number] mod [negative number]. If you want the modulo to behave the same way with negative numbers as it does with positive numbers, but just have the result be negative, then you need to make sure the divisor is also negative, since the modulo operation will always return a number with the same sign as the divisor.\\n\\nLastly, I use `math.trunc` instead of just using floor division `//` because of negative numbers. When dividing `x` by 10 and truncating the decimal, if the number is negative, then it would round down <i>away</i> from zero, when really, we want it to round up <i>towards</i> zero.\\n\\n# Code\\n```\\nclass Solution:\\n def reverse(self, x: int) -> int:\\n MAX_INT = 2 ** 31 - 1 # 2,147,483,647\\n MIN_INT = -2 ** 31 #-2,147,483,648\\n reverse = 0\\n\\n while x != 0:\\n if reverse > MAX_INT / 10 or reverse < MIN_INT / 10:\\n return 0\\n digit = x % 10 if x > 0 else x % -10\\n reverse = reverse * 10 + digit\\n x = math.trunc(x / 10)\\n\\n return reverse\\n\\n```" | 5 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Guys check my solution and tell me if it is wrong || and comment the Solution | reverse-integer | 0 | 1 | ***Guys PLEASE UPVOTE***\n\n\n# Code\n```\nclass Solution:\n def reverse(self, x: int) -> int:\n\n MIN=-2**31\n MAX=(2**31)-1\n k=0\n while x!=0:\n if k> MAX/10 or k<MIN/10 :\n return 0\n digit = x%10 if x>0 else x%-10\n k=k*10 + digit\n ... | 3 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Python | Simple Reverse String | O(n) | 90% T 87% S | reverse-integer | 0 | 1 | **Simple Reverse String Conversion**\n\n```\nclass Solution:\n def reverse(self, x: int) -> int:\n # positive case\n if x > 0:\n \n if int(str(x)[::-1]) > pow(2, 31) - 1: # out of bounds\n return 0\n \n return(int(str(x)[::-1])) # return revers... | 1 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Reverse Integer | reverse-integer | 0 | 1 | # Code\n```\nclass Solution:\n def reverse(self, x: int) -> int:\n x=list(str(x))\n x.reverse()\n k=""\n f=0\n for i in x:\n if(i!="-"):\n k+=i\n else:\n f=1\n k=int(k)\n if(k>(2**31)-1):\n return 0\n ... | 2 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
PYTHON SOLUTION | reverse-integer | 0 | 1 | # Intuition\nEasy solution in python\n\n# Code\n```\nMIN=-2**31\nMAX=(2**31)-1\nclass Solution:\n def __init__(self):\n self.rev=0\n self.is_neg=False\n def reverse(self, x: int) -> int:\n if x < 0:\n self.is_neg=True\n x=abs(x)\n while(x!=0):\n digit=x... | 12 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Iterative Python3 Solution | reverse-integer | 0 | 1 | # Intuition\nUtilize `//` (floor) and `%` (modulus) functions to break down the integer into its base-10 digits.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Instantiate DS to store digits of reversed number.\n2. Store digits in array as you use floor and modulus to break the number down, it... | 1 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
easy python code | reverse-integer | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Easy in Python | reverse-integer | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-231, 231 - 1]`, then return `0`.
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
**Example 1:**
**Input:** x = 123
... | null |
Solution | string-to-integer-atoi | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Fast and simpler DFA approach (Python 3) | string-to-integer-atoi | 0 | 1 | A fast and (probably) **much simpler and easier to understand DFA solution** than the others when you search for the keyword `DFA`:\n\n```python\nclass Solution:\n def myAtoi(self, str: str) -> int:\n value, state, pos, sign = 0, 0, 0, 1\n\n if len(str) == 0:\n return 0\n\n while pos ... | 286 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
C++/Python beats 100% dealing with boundary cases | string-to-integer-atoi | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAfter a lot of tries, it is solved, with many if-clauses and beats 100%.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Using do-while loop to deal with substring blank```\' \'```\'s at the beginning\n2. After th... | 4 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Python Solution - Passes all test cases | string-to-integer-atoi | 0 | 1 | # Intuition\nSimple problem itself, just need to pass test cases.\n\n# Approach\nSolve each test case one by one, submit, solve next failed test case.\n\n# Complexity\n- Time complexity:\n $$O(n)$$\n\n- Space complexity:\n $$O(n)$$\n\n# Code\n```\nclass Solution:\n def myAtoi(self, s: str) -> int:\n s=s... | 1 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Python Very Intuitive with Comments | string-to-integer-atoi | 0 | 1 | ```\nclass Solution:\n def myAtoi(self, s: str) -> int:\n if not s:\n return 0\n\n # remove leading and trailing whitespace\n s = s.strip()\n\n # save sign if one exists\n pos = True\n if s and s[0] == \'-\':\n pos = False\n s = s[1:]\n ... | 5 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Beats : 90.02% [42/145 Top Interview Question] | string-to-integer-atoi | 0 | 1 | # Intuition\n*Paper and pen and try to figure out all the possible edge cases, The question was easy, but the question explanation was poor.No need to worry about the **least acceptance rate** that the question has.*\n\n# Approach\nThis code defines a class called Solution with a method named `myAtoi` which takes a str... | 5 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Best Solution || Python3 || 100% Working || Using Regex || | string-to-integer-atoi | 0 | 1 | # Approach\nUsed Regular Expression approach to solve..!\n\n# Code\n```\nimport re\nclass Solution:\n def myAtoi(self, s: str) -> int:\n s = s.strip()\n if len(s):\n if not s[0].isalpha():\n i = re.search(r"^(-\\d+)|^(\\+\\d+)|^(\\d+)",s)\n if i is not None:\n ... | 2 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Python Easy Solution | string-to-integer-atoi | 0 | 1 | ```\nclass Solution:\n def myAtoi(self, s: str) -> int:\n su,num,flag = 1,0,0\n s = s.strip()\n if len(s) == 0: return 0\n if s[0] == "-":\n su = -1\n for i in s:\n if i.isdigit():\n num = num*10 + int(i)\n flag = 1\n e... | 5 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
Python 3 step by step solution in code EASY | string-to-integer-atoi | 0 | 1 | \n```\nclass Solution:\n def myAtoi(self, s: str) -> int:\n # remove leading and trailing white space\n s = s.strip()\n if not s:\n return 0\n \n # determine the sign of the number\n sign = 1\n if s[0] == \'-\':\n sign = -1\n s = s[1:]... | 1 | 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:
1. Read in and ignore any leading whitespace.
2. Check if the next character (if not already at the end of the string) is `'-'` or `... | null |
✅2 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | palindrome-number | 1 | 1 | # Intuition:\nThe intuition behind this code is to reverse the entire input number and check if the reversed number is equal to the original number. If they are the same, then the number is a palindrome.\n\n# Approach 1: Reversing the Entire Number\n# Explanation:\n1. We begin by performing an initial check. If the inp... | 766 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Simplest Python3 solution.!! | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is the simplest solution.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nJust reverse the string and compare it.\n\n# Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\n<!-- Add your space complexit... | 2 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
[VIDEO] Visualization of Solution Using Modulo and Floor Division | palindrome-number | 0 | 1 | ERROR: type should be string, got "https://www.youtube.com/watch?v=OlTk8wM48ww\\n\\nThe idea here is that we don\\'t need to reverse all the digits, only <i>half</i> the digits. The first line checks some edge cases, and returns False immediately if the number is negative or ends with a 0 (with the exception of the number 0 itself). The loop then uses the modulo and floor division operators to reverse the digits and transfer them to the `half` variable.\\n\\nOnce the halfway point is reached, we return True if the two halves are equal to each other. If the number originally had an <i>odd</i> number of digits, then the two halves will be off by 1 digit, so we also remove that digit using floor division, then compare for equality.\\n# Code\\n```\\nclass Solution(object):\\n def isPalindrome(self, x):\\n if x < 0 or (x != 0 and x % 10 == 0):\\n return False\\n\\n half = 0\\n while x > half:\\n half = (half * 10) + (x % 10)\\n x = x // 10\\n\\n return x == half or x == half // 10\\n```\\n\\n# Alternate solution\\n```\\nclass Solution(object):\\n def isPalindrome(self, x):\\n x = str(x)\\n return x == x[::-1]\\n```\\nAlternate solution: turn the number into a string, reverse it, and see if they\\'re equal. This is the simplest solution, but the question does challenge us to solve it <i>without</i> turning the number into a string.\\n" | 11 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Python 3 -> 1 solution is 89.20% faster. 2nd is 99.14% faster. Explanation added | palindrome-number | 0 | 1 | **Suggestions to make them better are always welcomed.**\n\n**Solution 1: 89.20% faster**\nThis is the easiest way to check if integer is palindrome. \n\nConvert the number to string and compare it with the reversed string.\n\nI wrote this working solution first and then found in the description that we need to solve t... | 656 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
🔥🔥🔥Python Eazy to understand beat 95% and simple 🔥🔥🔥🔥🚀 | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
🚀C++ || Java || Python || Two Methods || Explained Intuition🚀 | palindrome-number | 1 | 1 | # Problem Description\n**Given** an integer x, return **true** if x is a **palindrome**, and **false** otherwise.\n\n**Palindrome** is a **word**, **phrase**, **number**, or **other sequence of characters** that **reads** the **same** **forward** and **backward**. In simpler terms, it\'s something that `remains unchang... | 16 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
✅ Beats 98.37% using Python 3 || Clean and Simply ✅ | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. --> \nTo solve this problem, I considered the number of cases to account for and the potential subcases within each.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI approached this problem by considering two cases: ... | 0 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
this is it lol | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Amazing Awesome Solution | palindrome-number | 0 | 1 | Don\'t need False if there is True\n\n# Code\n```\nclass Solution:\n def isPalindrome(self, x: int) -> bool:\n\n if str(x) == str(x)[::-1]:\n return True\n``` | 1 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
✅DETAILED EXPLANATION | Beginner Friendly🔥🔥🔥 | PYTHON | | palindrome-number | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given code is implementing a method isPalindrome in the Solution class. This method takes an integer x as input and checks whether it is a palindrome or not.\n\nHere\'s how the code works:\n\nThe method converts the integer x into a l... | 2 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Python Integer Palindrome Checker | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can convert the integer to a string and check if the string is a palindrome by comparing it with its reverse.\n\nWe can see from the examples that negative numbers are not palindromes because they start with - and when reversed the - s... | 3 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Python simple one line solution | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIntution is to check whether the given integer is a palindrome\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwhat i have done here is convert the integer into list and using slicing notation reverse matched\n# Co... | 5 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Palindrome without using convertation to str | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe hint was not to use convertation x to string , so I used tricks of division. \n\n# Approach\nWe start from the latest digit of initial number and build reverted number. Then check is real number equals to reverted and returns the resu... | 11 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Python code just visit the code | palindrome-number | 0 | 1 | # Approach\n1. first we have to check weather it is x < 0 then return false.\n2. then we have to save one temp memory as copy i used u can use your own variables. \n3. we use the while for loop to get result, for that take result with default value as 0.\n4. In while loop first we have to find reminder using (x%10),th... | 2 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Easy way to solve the Palindrome in Python3 | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
✅💡100% Acceptance Rate with ❣️Easy and Detailed Explanation - O(log10(x)) solution 💡😄 | palindrome-number | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo check if an integer is a palindrome, we reverse the integer and compare it with the original number. If they are the same, the number is a palindrome. However, we need to handle some special cases like negative numbers and numbers endi... | 6 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Python one-line solution with explanation | palindrome-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nString has method to reverse\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwith reversing it is possible to write in one line\n\'[::]\' this means print all, and this \'[::-1]\' reverses, it is mostly used with lis... | 39 | Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_.
**Example 1:**
**Input:** x = 121
**Output:** true
**Explanation:** 121 reads as 121 from left to right and from right to left.
**Example 2:**
**Input:** x = -121
**Output:** false
**Explanation:** From left to right, i... | Beware of overflow when you reverse the integer. |
Solution | regular-expression-matching | 1 | 1 | ```C++ []\nclass Solution {\npublic:\n bool isMatch(string s, string p) {\n int n = s.length(), m = p.length();\n bool dp[n+1][m+1];\n memset(dp, false, sizeof(dp));\n dp[0][0] = true;\n \n for(int i=0; i<=n; i++){\n for(int j=1; j<=m; j++){\n if(p[... | 461 | 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:... | null |
Beats 99% Easy Solution | regular-expression-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 2 | 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:... | null |
[ Beats 98% ] Regular Expression Matching using Dynamic Programming in Python | regular-expression-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem can be solved by using dynamic programming. We can define dp(i, j) as the boolean value indicating whether the substring s[i:] matches the pattern p[j:].\n# Approach\n<!-- Describe your approach to solving the problem. -->\nW... | 17 | 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:... | null |
Python solution | regular-expression-matching | 0 | 1 | \n\n# Code\n```\nclass Solution:\n\n def func(self, i,j) :\n\n if self.dp[i][j] != -1 :\n return self.dp[i][j]\n\n if i==len(self.s) and j==len(self.p) :\n return True \n if i>=len(self.s):\n \n while(j<len(self.p)-1) :\n if self.p[j+1] ... | 1 | 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:... | null |
[0ms][1LINER][100%][Fastest Solution Explained] O(n) time complexity | O(n) space complexity | regular-expression-matching | 1 | 1 | (Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, ***please upvote*** this post.)\n***Take care brother, peace, love!***\n\n```\n```\n\nThe best result for the code below is ***0ms / 38.2MB*** (beats 92.04% / 24.00%).\n* *** Python ***\n\n```\n\n def isMa... | 19 | 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:... | null |
[Fastest Solution Explained][0ms][100%] O(n)time complexity O(n)space complexity | regular-expression-matching | 1 | 1 | \n(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, ***please upvote*** this post.)\n***Take care brother, peace, love!***\n\n```\n```\n\nThe best result for the code below is ***0ms / 3.27MB*** (beats 99.04% / 90.42%).\n* *** Java ***\n\n```\n\npublic boole... | 13 | 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:... | null |
one-line python solution | regular-expression-matching | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 5 | 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:... | null |
dp / python3 / time O(mn) / space O(mn) | regular-expression-matching | 0 | 1 | This problem can be solved using dynamic programming. Let dp[i][j] be a boolean indicating whether the first i characters of s match the first j characters of p. We can initialize dp[0][0] = True because an empty string matches an empty pattern.\n\nFor the first row dp[0][j], we need to consider two cases: if p[j-1] is... | 6 | 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:... | null |
✅Best Method 🔥 || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | container-with-most-water | 1 | 1 | # Intuition:\nThe two-pointer technique starts with the widest container and moves the pointers inward based on the comparison of heights. \nIncreasing the width of the container can only lead to a larger area if the height of the new boundary is greater. By moving the pointers towards the center, we explore containers... | 627 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
✅Best Method 🔥 || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | container-with-most-water | 1 | 1 | # Intuition:\nThe two-pointer technique starts with the widest container and moves the pointers inward based on the comparison of heights. \nIncreasing the width of the container can only lead to a larger area if the height of the new boundary is greater. By moving the pointers towards the center, we explore containers... | 627 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
🔥Beats 100% | 🔥O(n) Solution With Detailed Example💡| C++ | Java | Python | Javascript | C | Ruby | container-with-most-water | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves finding two lines in a set of vertical lines (represented by an array of heights) that can form a container to hold the maximum amount of water. The water\'s capacity is determined by the height of the shorter line an... | 73 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
🔥Beats 100% | 🔥O(n) Solution With Detailed Example💡| C++ | Java | Python | Javascript | C | Ruby | container-with-most-water | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves finding two lines in a set of vertical lines (represented by an array of heights) that can form a container to hold the maximum amount of water. The water\'s capacity is determined by the height of the shorter line an... | 73 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
[C++] [Python] Brute Force Approach || Too Easy || Fully Explained | container-with-most-water | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nSuppose we have the following input vector:\n```\nvector<int> hit = {1, 8, 6, 2, 5, 4, 8, 3, 7};\n```\n\nNow, let\'s go through the function step by step:\n\n1. Initialize `mx` (maximum area) to INT_MIN (the minimum value that can be represented by th... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
[C++] [Python] Brute Force Approach || Too Easy || Fully Explained | container-with-most-water | 0 | 1 | # Approach\n<!-- Describe your approach to solving the problem. -->\nSuppose we have the following input vector:\n```\nvector<int> hit = {1, 8, 6, 2, 5, 4, 8, 3, 7};\n```\n\nNow, let\'s go through the function step by step:\n\n1. Initialize `mx` (maximum area) to INT_MIN (the minimum value that can be represented by th... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
container-with-most-water with O(n) time complexity | container-with-most-water | 0 | 1 | \n# Approach\nBrute Force approach would be:\n Traversing through the array, considering each element of the array and calcualting the container area with the rest of the elements in the array would give the solution but results in O(n^2) time complexity, the code snippet would be:\n```\nCode block\narea_tracker=0\n... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
container-with-most-water with O(n) time complexity | container-with-most-water | 0 | 1 | \n# Approach\nBrute Force approach would be:\n Traversing through the array, considering each element of the array and calcualting the container area with the rest of the elements in the array would give the solution but results in O(n^2) time complexity, the code snippet would be:\n```\nCode block\narea_tracker=0\n... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Container with most water | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Container with most water | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Easy Python Solution : beats 91.96%: With GREAT explanation | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet us take the two edges as the container walls and calculate the water in them.\n\nSo now we change the smaller wall.THE reason for NOT Changing the bigger wall is that the amount of water would not increase no matter the size of the bi... | 4 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Easy Python Solution : beats 91.96%: With GREAT explanation | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet us take the two edges as the container walls and calculate the water in them.\n\nSo now we change the smaller wall.THE reason for NOT Changing the bigger wall is that the amount of water would not increase no matter the size of the bi... | 4 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
[VIDEO] Visualization and Intuitive Proof of Greedy Solution | container-with-most-water | 0 | 1 | https://youtu.be/Kb20p6zy_14\n\nThe strategy is to start with the container of the <i>longest</i> width and move the sides inwards one by one to see if we can get a larger area by shortening the width but getting a taller height. But how do we know which side to move?\n\nThe key insight here is that moving the <i>longe... | 6 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
[VIDEO] Visualization and Intuitive Proof of Greedy Solution | container-with-most-water | 0 | 1 | https://youtu.be/Kb20p6zy_14\n\nThe strategy is to start with the container of the <i>longest</i> width and move the sides inwards one by one to see if we can get a larger area by shortening the width but getting a taller height. But how do we know which side to move?\n\nThe key insight here is that moving the <i>longe... | 6 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
[Python] - Clean & Simple Math Solution - Using Two Pointer | container-with-most-water | 0 | 1 | # Code\n```\nclass Solution:\n def maxArea(self, h: List[int]) -> int:\n n = len(h)\n\n l, r = 0, n - 1\n\n ans = 0\n while l <= r:\n ans = max(ans, (r - l) * min(h[l], h[r]))\n if h[l] < h[r]: l += 1\n else: r -= 1\n return ans\n``` | 3 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
[Python] - Clean & Simple Math Solution - Using Two Pointer | container-with-most-water | 0 | 1 | # Code\n```\nclass Solution:\n def maxArea(self, h: List[int]) -> int:\n n = len(h)\n\n l, r = 0, n - 1\n\n ans = 0\n while l <= r:\n ans = max(ans, (r - l) * min(h[l], h[r]))\n if h[l] < h[r]: l += 1\n else: r -= 1\n return ans\n``` | 3 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
2 pointers | container-with-most-water | 0 | 1 | \n# Approach\nUsing 2 pointers that are set to 0 and n-1 at first, we move them towards the middle to find the best container. We are starting at the end because then we get the best base of rectangle, then we move worse pointer (that one pointing at smaller wall) towards the middle \nto try finding. Loop ends when poi... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
2 pointers | container-with-most-water | 0 | 1 | \n# Approach\nUsing 2 pointers that are set to 0 and n-1 at first, we move them towards the middle to find the best container. We are starting at the end because then we get the best base of rectangle, then we move worse pointer (that one pointing at smaller wall) towards the middle \nto try finding. Loop ends when poi... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Two Pointer Logic-->Python3 | container-with-most-water | 0 | 1 | \n\n# Two Pointer Logic : TC----->O(N)\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n left,right,answer=0,len(height)-1,0\n while left<=right:\n area=min(height[right],height[left])*(right-left)\n answer=max(answer,area)\n if height[right]>height... | 63 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Two Pointer Logic-->Python3 | container-with-most-water | 0 | 1 | \n\n# Two Pointer Logic : TC----->O(N)\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n left,right,answer=0,len(height)-1,0\n while left<=right:\n area=min(height[right],height[left])*(right-left)\n answer=max(answer,area)\n if height[right]>height... | 63 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
✔️ [Python3] GREEDY TWO POINTERS ~(˘▾˘~), Explained | container-with-most-water | 0 | 1 | **UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nFirst, we check the widest possible container starting from the first line to the last one. Next, we ask ourselves, how is it possible to form an even bigger container? Every time we narrow the container, the width b... | 185 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
✔️ [Python3] GREEDY TWO POINTERS ~(˘▾˘~), Explained | container-with-most-water | 0 | 1 | **UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nFirst, we check the widest possible container starting from the first line to the last one. Next, we ask ourselves, how is it possible to form an even bigger container? Every time we narrow the container, the width b... | 185 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
[Python] Constructive and Intuitive Solution in Linear Time, The Best | container-with-most-water | 0 | 1 | # Intuition\nWe would like to arrive at a constructive solution that is easily seen as correct (not missing any options), while running in linear time. This is different from the regular approach of moving left or right index one at a time, which requires an elaborate proof to use (correctness is not intuitive).\n\n# A... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
[Python] Constructive and Intuitive Solution in Linear Time, The Best | container-with-most-water | 0 | 1 | # Intuition\nWe would like to arrive at a constructive solution that is easily seen as correct (not missing any options), while running in linear time. This is different from the regular approach of moving left or right index one at a time, which requires an elaborate proof to use (correctness is not intuitive).\n\n# A... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
✅Worst method 🔥|| Python3 || Beginner Un-Friendly || Abysmal unreadable one liner. 🔥Beats 26% 🔥 | container-with-most-water | 0 | 1 | # Intuition\nAn esoteric solution to a reasonable interview question!\n\n# Approach\nSolve normally using two pointer approach. Purposefully obfuscate to one line.\n\nUses the exec() function from Python to encode a solution into a one-line string with escape codes.\n\n\\- Please, do not do this in an interview.\n\n# C... | 13 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
✅Worst method 🔥|| Python3 || Beginner Un-Friendly || Abysmal unreadable one liner. 🔥Beats 26% 🔥 | container-with-most-water | 0 | 1 | # Intuition\nAn esoteric solution to a reasonable interview question!\n\n# Approach\nSolve normally using two pointer approach. Purposefully obfuscate to one line.\n\nUses the exec() function from Python to encode a solution into a one-line string with escape codes.\n\n\\- Please, do not do this in an interview.\n\n# C... | 13 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Easy solution Omegalul | container-with-most-water | 0 | 1 | # Intuition\n2 pointers, left and right, see all possibilities, and move whnichever is smaller\n# Code\n```\nclass Solution:\n def maxArea(self, li: List[int]) -> int:\n sussyballs = 0\n p1 = 0\n p2 = len(li) - 1\n\n while p1 < p2:\n girth = p2 - p1\n length = min(li... | 0 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Easy solution Omegalul | container-with-most-water | 0 | 1 | # Intuition\n2 pointers, left and right, see all possibilities, and move whnichever is smaller\n# Code\n```\nclass Solution:\n def maxArea(self, li: List[int]) -> int:\n sussyballs = 0\n p1 = 0\n p2 = len(li) - 1\n\n while p1 < p2:\n girth = p2 - p1\n length = min(li... | 0 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Alternative O(N) solution | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to have a sorted (max to min) heights and their corresponding indices.\nOnce we have these values, we can iterate from the max heights to min heights, where the min heights will be the limiting height for any possible position pai... | 0 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Alternative O(N) solution | container-with-most-water | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to have a sorted (max to min) heights and their corresponding indices.\nOnce we have these values, we can iterate from the max heights to min heights, where the min heights will be the limiting height for any possible position pai... | 0 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Python3 | container-with-most-water | 0 | 1 | # Complexity\n- Time complexity: O(n)\n\n# Code\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n left, right = 0, len(height) - 1 # Initialize two pointers, left and right, pointing to the start and end of the height list respectively.\n out = 0 # Initialize the maximum area to ... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Python3 | container-with-most-water | 0 | 1 | # Complexity\n- Time complexity: O(n)\n\n# Code\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n left, right = 0, len(height) - 1 # Initialize two pointers, left and right, pointing to the start and end of the height list respectively.\n out = 0 # Initialize the maximum area to ... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Beats 99.72% of code | container-with-most-water | 0 | 1 | # Intuition\nUsing two-pointer is the best approach to solve this problem.\n\n\n# Complexity\n- Time complexity:\n- Big(N)\n\n- Space complexity:\n- Big(1)\n\n# Code\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n l = 0\n size = len(height) - 1\n r = size\n maxAmoun... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
Beats 99.72% of code | container-with-most-water | 0 | 1 | # Intuition\nUsing two-pointer is the best approach to solve this problem.\n\n\n# Complexity\n- Time complexity:\n- Big(N)\n\n- Space complexity:\n- Big(1)\n\n# Code\n```\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n l = 0\n size = len(height) - 1\n r = size\n maxAmoun... | 1 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
✅C++ Solution | | Python | | Java | | Easy Understanding | | Two-Pointer Approach | container-with-most-water | 1 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor maximinzing the area , breadth should be maximum , so thats why we start our "j" pointer from the last and "i" pointer to the start .\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n- Space com... | 35 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width ... |
✅C++ Solution | | Python | | Java | | Easy Understanding | | Two-Pointer Approach | container-with-most-water | 1 | 1 | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor maximinzing the area , breadth should be maximum , so thats why we start our "j" pointer from the last and "i" pointer to the start .\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n- Space com... | 35 | You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`.
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return _the maximum amount of water... | The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle.
Area = length of shorter vertical line * distance between lines
We can definitely get the maximum width contai... |
Simple Python solution with minimal lines O(n) | integer-to-roman | 0 | 1 | # Intuition\nIf the number isn\'t in the table of roman mappings, we need to find the nearest roman below it and then subtract it, then find the mapping for the rest of the number all over again. How?\n\n# Approach\nAfter creating a mapping of the requirement constraints, make a list of keys sorted reverse. Iterate dow... | 1 | 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 adde... | null |
✔️ Python's Simple and Easy to Understand Solution | 99% Faster 🔥 | integer-to-roman | 0 | 1 | **\uD83D\uDD3C IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D**\n\nVisit this blog to learn Python tips and techniques and to find a Leetcode solution with an explanation: https://www.python-techs.com/\n\n**Solution:**\n```\nclass Solution:\n def intToRoman(self, num: int) -> str:\n # Creating Dict... | 170 | 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 adde... | null |
brutish but efficient | integer-to-roman | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 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 adde... | null |
probably brute force but works :3 | integer-to-roman | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | 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 adde... | null |
Dict change Python solution | integer-to-roman | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | 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 adde... | null |
Awesome Python Solution | integer-to-roman | 0 | 1 | \n\n# Python Solution\n```\nclass Solution:\n def intToRoman(self, num: int) -> str:\n M=["","M","MM","MMM"]\n C=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"]\n X=["","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"]\n I=["","I","II","III","IV","V","VI","VII","VIII","IX"]\n ret... | 37 | 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 adde... | null |
Beats 99.55% / Brute force / Easy to understand / Beginner code | integer-to-roman | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 8 | 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 adde... | null |
Eas Sol | integer-to-roman | 0 | 1 | \n```\nvalue = [1000,900,500,400,100,90,50,40,10,9,5,4,1]\nroman = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]\n\nclass Solution:\n def intToRoman(self, N: int) -> str:\n ans = ""\n for i in range(13):\n while N >= value[i]:\n ans += roman[i]\n N... | 1 | 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 adde... | null |
Take this simple sol with python | integer-to-roman | 0 | 1 | # Code\n```\nclass Solution:\n def intToRoman(self, num: int) -> str:\n roman_mapping = {\n 1000: \'M\',\n 900: \'CM\',\n 500: \'D\',\n 400: \'CD\',\n 100: \'C\',\n 90: \'XC\',\n 50: \'L\',\n 40: \'XL\',\n 10: \... | 6 | 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 adde... | null |
Fastest Python solution using mapping | integer-to-roman | 0 | 1 | ```\nclass Solution:\n def intToRoman(self, num: int) -> str:\n i=1\n dic={1:\'I\',5:\'V\',10:\'X\',50:\'L\',100:\'C\',500:\'D\',1000:\'M\'}\n s=""\n while num!=0:\n y=num%pow(10,i)//pow(10,i-1)\n if y==5:\n s=dic[y*pow(10,i-1)]+s\n elif y==... | 18 | 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 adde... | null |
✅Best Method || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | roman-to-integer | 1 | 1 | **Certainly! Let\'s break down the code and provide a clear intuition and explanation, using the examples "IX" and "XI" to demonstrate its functionality.**\n\n# Intuition:\nThe key intuition lies in the fact that in Roman numerals, when a smaller value appears before a larger value, it represents subtraction, while whe... | 1,369 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Hash Table Concept Python3 | roman-to-integer | 0 | 1 | \n# Hash Table in python\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n roman={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}\n number=0\n for i in range(len(s)-1):\n if roman[s[i]] < roman[s[(i+1)]]:\n number-=roman[s[i]]\n else:\n ... | 323 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Clean Python, beats 99.78%. | roman-to-integer | 0 | 1 | The Romans would most likely be angered by how it butchers their numeric system. Sorry guys.\n\n```Python\nclass Solution:\n def romanToInt(self, s: str) -> int:\n translations = {\n "I": 1,\n "V": 5,\n "X": 10,\n "L": 50,\n "C": 100,\n "D": 50... | 1,920 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Simple solution with Hashing in Python3 | roman-to-integer | 0 | 1 | # Intuition\nHere we have `s` as **Roman Integer** and our goal is to convert it into **decimal**.\n\n# Approach\nSimply use **HashTable** to map all the **possible** combinations.\nIn many cases such combs as `\'I\'`, `\'IV\'` etc. are **valid**, we should check for **the largest**.\n\n# Complexity\n- Time complexity:... | 1 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Mastering IF ELIF in Python | roman-to-integer | 0 | 1 | # SOlution in Python\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n s += " "\n answer = 0\n for i in range(len(s)):\n if s[i] == \'I\':\n if s[i+1] in {\'V\', \'X\'}: \n answer -= 1\n else:\n answer ... | 1 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Python + functools.reduce + operator | roman-to-integer | 0 | 1 | # Intuition\n\nUsing `reduce` function from module `functools`\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n# Code\n```\nimport functools as fn\nimport operator as op\n\nclass Solution:\n lookup_table = {\n "I": 1,\n "V": 5,\n "X": 10,\n "L": 50,\n "C": 100... | 1 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
🔥 Python || Easily Understood ✅ || Faster than 98% || Less than 76% || O(n) | roman-to-integer | 0 | 1 | Code:\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n roman_to_integer = {\n \'I\': 1,\n \'V\': 5,\n \'X\': 10,\n \'L\': 50,\n \'C\': 100,\n \'D\': 500,\n \'M\': 1000,\n }\n s = s.replace("IV", "IIII").re... | 402 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Easy-to-understand Solution for Python | roman-to-integer | 0 | 1 | Explanation:\n\n1- class Solution:: Defines a class named "Solution."\n\n2- def romanToInt(self, s: str) -> int:: Defines a function within the class that takes a string of Roman numerals (s) and returns an integer. The function is a method of the class (self refers to the instance of the class).\n\n3- roman_list = {\'... | 2 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
[VIDEO] Visualization of Two Different Approaches | roman-to-integer | 0 | 1 | https://www.youtube.com/watch?v=tsmrUi5M1JU\n\n<b>Method 1:</b>\nThis solution takes the approach incorporating the general logic of roman numerals into the algorithm. We first create a dictionary that maps each roman numeral to the corresponding integer. We also create a total variable set to 0.\n\nWe then loop over... | 12 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
✅🔥Beats 99.99% || 📈Easy solution with O(n) Approach ✔| C++ | Python | Java | Javascript | roman-to-integer | 1 | 1 | # \u2705Do upvote if you like the solution and explanation please \uD83D\uDE80\n\n# \u2705Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this code is to iterate through the Roman numeral string from right to left, converting each symbol to its corresponding intege... | 25 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
[python] simple solution !! complexity -O(n) | roman-to-integer | 0 | 1 | https://github.com/parasdwi/Practice/blob/main/Roman_to_Integer.py | 1 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
👾C#, Java, Python3,JavaScript Solution (Easy-Understanding) | roman-to-integer | 1 | 1 | ### C#,Java,Python3,JavaScript different solution with explanation\n**\u2B50[https://zyrastory.com/en/coding-en/leetcode-en/leetcode-13-roman-to-integer-solution-and-explanation-en/](https://zyrastory.com/en/coding-en/leetcode-en/leetcode-13-roman-to-integer-solution-and-explanation-en/)\u2B50**\n\n**\uD83E\uDDE1See ne... | 25 | 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 ones added... | Problem is simpler to solve by working the string from back to front and using a map. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.