question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
flip-string-to-monotone-increasing | Memo -> Tabulation -> Space Optimization -> Code Refactor | memo-tabulation-space-optimization-code-wbwu7 | \n# Memo -> Tabulation -> Space Optimization -> Code Refactor\n# Best Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space | mr_optimizer | NORMAL | 2023-01-17T13:33:00.746356+00:00 | 2023-01-17T13:33:00.746391+00:00 | 417 | false | \n# Memo -> Tabulation -> Space Optimization -> Code Refactor\n# Best Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Memo Code\n```\n int memo[100001][2];\n int dp(string &s, int i,... | 6 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 2 |
flip-string-to-monotone-increasing | Python - Picture/Video Solution | python-picturevideo-solution-by-cheatcod-vwb5 | I have explained the entire intuition here.\n\nIf this was helpful, please Upvote, like the video and subscribe for more such content.\n\n# Memoization\n\n\n\n\ | cheatcode-ninja | NORMAL | 2023-01-17T13:20:49.077850+00:00 | 2023-01-17T13:26:40.968331+00:00 | 222 | false | I have explained the entire intuition [here](https://youtu.be/t5-RdgOkYe4).\n\nIf this was helpful, please Upvote, like the video and subscribe for more such content.\n\n# Memoization\n\n\n\n\nThese are the val... | 6 | 0 | ['Dynamic Programming', 'Python3'] | 0 |
flip-string-to-monotone-increasing | 100% javascript fast very easy to understand with video explanation! | 100-javascript-fast-very-easy-to-underst-2flp | Here is video for explain if it is helpful please subscribe! :\n\nhttps://youtu.be/-m47DQxavnY\n\n\n\n# Code\n\n/**\n * @param {string} s\n * @return {number}\n | rlawnsqja850 | NORMAL | 2023-01-17T01:29:27.131620+00:00 | 2023-01-17T01:29:27.131660+00:00 | 772 | false | Here is video for explain if it is helpful please subscribe! :\n\nhttps://youtu.be/-m47DQxavnY\n\n\n\n# Code\n```\n/**\n * @param {string} s\n * @return {number}\n */\nvar minFlipsMonoIncr = function(s) {\n... | 6 | 0 | ['JavaScript'] | 3 |
flip-string-to-monotone-increasing | Easy C++ solution in O(N) | easy-c-solution-in-on-by-tejas702-10cs | \nclass Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n int res = 0;\n int c1 = 0;\n for(char c : s){\n if(c == \'0\ | tejas702 | NORMAL | 2021-08-10T07:47:23.787903+00:00 | 2021-08-10T07:47:39.547778+00:00 | 501 | false | ```\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n int res = 0;\n int c1 = 0;\n for(char c : s){\n if(c == \'0\'){\n if(c1>0)res+=1;\n }else{\n c1+=1; \n }\n res=min(res,c1);\n }\n retu... | 6 | 2 | ['String', 'C'] | 0 |
flip-string-to-monotone-increasing | Java Solution - O(N) time and O(1) space | java-solution-on-time-and-o1-space-by-at-ors0 | \nclass Solution {\n public int minFlipsMonoIncr(String S) {\n int zeroOnRight = 0;\n for(int i = 0; i < S.length(); i++){\n if(S.ch | itsmastersam | NORMAL | 2020-05-11T17:57:08.752730+00:00 | 2020-05-11T17:57:08.752782+00:00 | 521 | false | ```\nclass Solution {\n public int minFlipsMonoIncr(String S) {\n int zeroOnRight = 0;\n for(int i = 0; i < S.length(); i++){\n if(S.charAt(i) == \'0\'){\n zeroOnRight++;\n }\n }\n // partition at beginning\n int ans = zeroOnRight;\n int ... | 6 | 0 | ['Java'] | 2 |
flip-string-to-monotone-increasing | dp c++ O(n) | dp-c-on-by-savecancel-5t6c | Runtime: 4 ms, faster than 99.25% of C++ online submissions for Flip String to Monotone Increasing.\nMemory Usage: 9.5 MB, less than 60.00% of C++ online submis | savecancel | NORMAL | 2019-12-27T04:41:04.823810+00:00 | 2019-12-27T04:41:04.823850+00:00 | 449 | false | Runtime: 4 ms, faster than 99.25% of C++ online submissions for Flip String to Monotone Increasing.\nMemory Usage: 9.5 MB, less than 60.00% of C++ online submissions for Flip String to Monotone Increasing.\n\n\nwe can optimize further by only cosidering previous locations \n\n\n```\nclass Solution {\npublic:\n int m... | 6 | 1 | ['Dynamic Programming'] | 1 |
flip-string-to-monotone-increasing | Java Super Easy to Understand O(n) Solution | java-super-easy-to-understand-on-solutio-dwqw | Just do two pass can do the Job.\nFirst pass: from left to right. if we want to convert all the numbers to 0, how many flips we need, save it to zero[i].\nSeco | x372p | NORMAL | 2018-10-21T04:41:30.827437+00:00 | 2018-10-21T04:41:30.827482+00:00 | 243 | false | Just do two pass can do the Job.\nFirst pass: from left to right. if we want to convert all the numbers to 0, how many flips we need, save it to zero[i].\nSecond pass: from right to left. if we want to convert all the numbers to 1, how many flips we need, save it to one[i].\n\nThen the answer is just min(zero[i] + one... | 6 | 1 | [] | 1 |
flip-string-to-monotone-increasing | C++ || No DP || Prefix & suffix sum | c-no-dp-prefix-suffix-sum-by-a__ky25-fdtf | Intuition\n Describe your first thoughts on how to solve this problem. \n In every point in string i.e. every index we have to check if you\n can miximize | A__ky25 | NORMAL | 2023-01-20T06:24:35.729063+00:00 | 2023-01-20T06:24:35.729108+00:00 | 75 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n In every point in string i.e. every index we have to check if you\n can miximize the flips.\n for example if string is 101010\n In i=k\n we will check if its possible of flip all 1\'s into 0\'s from\n 0 to k-1. \n ... | 5 | 0 | ['Suffix Array', 'Prefix Sum', 'C++'] | 0 |
flip-string-to-monotone-increasing | Two Most Intuitive Approaches✅ || Full Explanation✅||C++ | two-most-intuitive-approaches-full-expla-h4nx | Approach 1 :\n# Intuition (DP + Memoization)\nTo find minimum number of flips we would try to explore all possiblities i.e. whether we can make string monotone | Pushkar2111 | NORMAL | 2023-01-17T18:06:08.488454+00:00 | 2023-01-17T18:06:08.488497+00:00 | 313 | false | ### Approach 1 :\n# Intuition (DP + Memoization)\nTo find minimum number of flips we would try to explore all possiblities i.e. whether we can make string monotone by flipping the current bit or not. \n\n# Approach\nThere can be two possible cases :-\n - If the previous character is \'0\':\n Now this has also two p... | 5 | 0 | ['Dynamic Programming', 'C++'] | 1 |
flip-string-to-monotone-increasing | 🧑🏫 Java | DP | Fully Explained [Article] | java-dp-fully-explained-article-by-nadar-hg7x | Introduction\nIn contrast to solutions that post the code with a few words, I walk through my thinking process. The goal is to share my thoughts and hopefully t | nadaralp | NORMAL | 2023-01-17T09:29:09.519545+00:00 | 2023-01-17T09:55:23.870603+00:00 | 314 | false | # Introduction\nIn contrast to solutions that post the code with a few words, I walk through my thinking process. The goal is to share my thoughts and hopefully teach you something new today.\n\nNadar\n\n# Intuition\nInitially, I thought of approaching the problem using a greedy method. We have two choices to make at a... | 5 | 0 | ['Java'] | 1 |
flip-string-to-monotone-increasing | [C++/Java] Full Explanation🔥||Easy||TC O(n) || SC O(1) | cjava-full-explanationeasytc-on-sc-o1-by-j0ib | Problem Statement:\n> We will be given a string \u2018s\u2019 containing \u20180\u2019s and \u20181\u2019s arranged in some order,so we need to find out the NoO | abdul_muqeet715 | NORMAL | 2023-01-17T04:46:06.430400+00:00 | 2023-01-17T04:46:06.430448+00:00 | 102 | false | **Problem Statement:**\n> We will be given a string \u2018s\u2019 containing \u20180\u2019s and \u20181\u2019s arranged in some order,so we need to find out the NoOfFlips required for the given to string to make it monotonically increasing sequence(eg: **\u20180010\u2019** then the monotonically increasing sequence may... | 5 | 0 | ['Java'] | 3 |
flip-string-to-monotone-increasing | SIMPLE PYTHON SOLUTION | simple-python-solution-by-beneath_ocean-yj1d | 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 | beneath_ocean | NORMAL | 2023-01-17T04:30:00.537747+00:00 | 2023-01-17T04:42:58.085557+00:00 | 1,654 | false | # 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: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $... | 5 | 0 | ['Python3'] | 2 |
flip-string-to-monotone-increasing | python3 || Keep track of 1s and 0s | python3-keep-track-of-1s-and-0s-by-iter_-kgnl | O(n), O(1)\n\n```\nclass Solution:\n def minFlipsMonoIncr(self, s: str) -> int:\n S, ans = len(s), len(s)\n zero_count = s.count("0")\n | iter_next | NORMAL | 2023-01-17T01:40:21.180741+00:00 | 2023-01-17T01:40:21.180789+00:00 | 667 | false | O(n), O(1)\n\n```\nclass Solution:\n def minFlipsMonoIncr(self, s: str) -> int:\n S, ans = len(s), len(s)\n zero_count = s.count("0")\n ones_count = 0\n\n for j in range(S):\n ans = min(ans, zero_count+ones_count)\n \n if s[j] == "1":\n ones... | 5 | 0 | ['Iterator', 'Python', 'Python3'] | 1 |
flip-string-to-monotone-increasing | Java O(N) | One Pass | O(1) Space | Prefix-Suffix | java-on-one-pass-o1-space-prefix-suffix-u1wid | Intuition: We are returning the minimum of min( no. of 1s flipped to 0s in prefix , no. of 0s in suffix )\nAlgo:\n1. Right after we encounter our first 1, we st | shivam_taneja | NORMAL | 2022-07-14T19:23:18.875370+00:00 | 2022-07-21T17:49:15.958941+00:00 | 265 | false | **Intuition:** We are returning the minimum of **min(** no. of 1s flipped to 0s in prefix **,** no. of 0s in suffix **)**\n**Algo:**\n1. Right after we encounter our first 1, we start counting the **number of flips**\n```Java \nif(charAt == 0) countFlip++\nelse countOnes++;\n```\n2. Now at every iteration we make the `... | 5 | 0 | ['Suffix Array', 'Java'] | 0 |
flip-string-to-monotone-increasing | Python O(n) time | python-on-time-by-yorkshire-2bt1 | Iterate over S. For each index, find the number of zeros after that index (that need to be flipped to ones) and the number of ones before and including that ind | yorkshire | NORMAL | 2018-10-21T03:02:12.200507+00:00 | 2018-10-23T05:50:33.833585+00:00 | 420 | false | Iterate over S.
For each index, find the number of zeros after that index (that need to be flipped to ones) and the number of ones before and including that index (that need to be flipped to zeros).
Return the lowest number of flips required for any index.
```
def minFlipsMonoIncr(self, S):
n = len(S)
... | 5 | 1 | [] | 0 |
flip-string-to-monotone-increasing | 6 line python solution with explanation | 6-line-python-solution-with-explanation-a5ytq | Intuition\nMy first thgouht was to use dynamic programming to calculate a sliding window of zeroflips from left to right as well as oneflips from right to left | smanian | NORMAL | 2023-01-17T09:03:51.599321+00:00 | 2023-01-18T01:35:52.669661+00:00 | 183 | false | # Intuition\nMy first thgouht was to use dynamic programming to calculate a sliding window of zeroflips from left to right as well as oneflips from right to left and then to find the location in the middle that minimizes the number of flips. \n\nAfter working through an elaborate solution I learned that this problem ca... | 4 | 0 | ['Math', 'Python', 'Python3'] | 1 |
flip-string-to-monotone-increasing | Easiest to understand find the pt where max difference of 0 and 1 count exist | easiest-to-understand-find-the-pt-where-6tec2 | Intuition\n Describe your first thoughts on how to solve this problem. \nFinding the point where last 0 should be\n# Approach\n Describe your approach to solvin | Subhrajeet_Biswal | NORMAL | 2023-01-17T07:14:06.204702+00:00 | 2023-01-17T07:14:06.204744+00:00 | 49 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Finding the point where last 0 should be**\n# Approach\n<!-- Describe your approach to solving the problem. -->\nwe can do it by finding the place where there is max difference between c0&c1 ie **max(c0-c1)**\n# Complexity\n- Time compl... | 4 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | C++ ||Begineer Friendly|| Easy-Understanding|| No DP || Video solution | c-begineer-friendly-easy-understanding-n-afyz | Intuition\n Describe your first thoughts on how to solve this problem. \nC++ Clear Explaination ,Please support if you find it usefull. Can give me feedback in | CodeWithSky | NORMAL | 2023-01-17T05:48:17.583180+00:00 | 2023-01-17T05:50:44.480913+00:00 | 350 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**C++ Clear Explaination ,Please support if you find it usefull. Can give me feedback in comment for improvement.,will be very thankfull.**\n<iframe width="560" height="315" src="https://www.youtube.com/embed/MSXfEZC-pcw" title="YouTube v... | 4 | 0 | ['String', 'Dynamic Programming', 'Bit Manipulation', 'C++', 'Java'] | 0 |
flip-string-to-monotone-increasing | ✅C++ | easy solution | prefix sum✅ | c-easy-solution-prefix-sum-by-suraj_jha9-fxc0 | \n# Approach\nwe have three choices ==> all 0\'s,all 1\'s or (0\'s and 1\'s)\nout of these choices take min of them.\n\nfor third case : 0\'s followed by 1\'s\n | suraj_jha989 | NORMAL | 2023-01-17T05:00:51.960525+00:00 | 2023-01-17T05:00:51.960568+00:00 | 69 | false | \n# Approach\nwe have three choices ==> all 0\'s,all 1\'s or (0\'s and 1\'s)\nout of these choices take min of them.\n\nfor third case : 0\'s followed by 1\'s\nwe will try out all possible strings that we can make\n\nfor each idx i, we will form a string that has all zeros till "i\'th" idx(including i idx) \nand all 1\... | 4 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | ✅ easy and fast code | C++ | easy-and-fast-code-c-by-coding_menance-kmlx | Here is the solution for the question:\n\nC++ []\nclass Solution\n{\npublic:\n int minFlipsMonoIncr(string S)\n {\n int count_flip = 0, count_one = | coding_menance | NORMAL | 2023-01-17T03:32:26.342692+00:00 | 2023-01-17T03:32:26.342795+00:00 | 322 | false | Here is the solution for the question:\n\n``` C++ []\nclass Solution\n{\npublic:\n int minFlipsMonoIncr(string S)\n {\n int count_flip = 0, count_one = 0;\n for (auto i : S)\n { \n //keep track of all one (we will use count_one in else condition if we need) \n//if we want flip one into 0\n ... | 4 | 0 | ['C++'] | 3 |
flip-string-to-monotone-increasing | C++ || Easy to understand || PostFix Sum | c-easy-to-understand-postfix-sum-by-moha-ajoq | Intuition\n\n1) Traverse the string from left to right\n2) Whenever you encounter a \'1\' there would be 2 cases possible \n\t you can keep this as \'1\' , the | mohakharjani | NORMAL | 2023-01-17T02:07:07.919475+00:00 | 2023-01-17T03:17:57.042383+00:00 | 1,520 | false | Intuition\n\n1) Traverse the string from left to right\n2) Whenever you encounter a \'1\' there would be 2 cases possible \n\t* you **can keep this as \'1\'** , then all the chars at right should be \'1\' to make it increasing,\n\t so flip all the \'0\'s (towards right) to \'1\'s\n\t * **or flip the curr \'1\' to \'0... | 4 | 0 | ['C', 'C++'] | 2 |
flip-string-to-monotone-increasing | 3 Solution || Brute to Best || Complexity | 3-solution-brute-to-best-complexity-by-s-02wu | Intuition\n Describe your first thoughts on how to solve this problem. \nspecial mention : prathz for this approach\nPrefix sum \n\n# Approach\n Describe your | sunnyjha1512002 | NORMAL | 2023-01-17T02:02:02.621321+00:00 | 2023-01-17T02:02:02.621357+00:00 | 472 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nspecial mention : [prathz](https://leetcode.com/problems/flip-string-to-monotone-increasing/solutions/3061177/c-prefix-sum/?orderBy=hot) for this approach\nPrefix sum \n\n# Approach\n<!-- Describe your approach to solving the problem. --... | 4 | 0 | ['Array', 'Suffix Array', 'Prefix Sum', 'C++'] | 3 |
flip-string-to-monotone-increasing | DAILY LEETCODE SOLUTION || EASY C++ SOLUTION | daily-leetcode-solution-easy-c-solution-kkcn1 | \n//Memoisation\nclass Solution {\npublic:\n int solve(int idx,int prev,string &s,vector<vector<int>>& dp){\n if(idx==s.size()){\n return 0 | pankaj_777 | NORMAL | 2023-01-17T00:33:52.916770+00:00 | 2023-01-17T01:05:18.706180+00:00 | 639 | false | ```\n//Memoisation\nclass Solution {\npublic:\n int solve(int idx,int prev,string &s,vector<vector<int>>& dp){\n if(idx==s.size()){\n return 0;\n }\n if(dp[idx][prev]!=-1) return dp[idx][prev];\n if(prev){\n return dp[idx][prev]=(s[idx]==\'0\')+solve(idx+1,prev,s,dp)... | 4 | 0 | ['Dynamic Programming', 'Memoization', 'C++'] | 2 |
flip-string-to-monotone-increasing | C++ | Memoization | Easy Code | c-memoization-easy-code-by-letthecodebe-euky | Code\n\nclass Solution {\npublic:\n int helper(int i, int prev, string &s, int n, vector<vector<int>> &dp){\n if(i>=n) return 0;\n\n if(dp[i][p | letthecodebe | NORMAL | 2023-01-12T12:46:29.272726+00:00 | 2023-01-12T12:46:29.272765+00:00 | 578 | false | # Code\n```\nclass Solution {\npublic:\n int helper(int i, int prev, string &s, int n, vector<vector<int>> &dp){\n if(i>=n) return 0;\n\n if(dp[i][prev] != -1) return dp[i][prev];\n\n int ans = INT_MAX;\n\n if(s[i]==\'0\'){\n if(prev == 0){\n ans = min(ans,min(1 ... | 4 | 0 | ['String', 'Dynamic Programming', 'Recursion', 'Memoization', 'C++'] | 1 |
flip-string-to-monotone-increasing | [JAVA] BEATS 100.00% MEMORY/SPEED 0ms // APRIL 2022 | java-beats-10000-memoryspeed-0ms-april-2-rysz | \n\tclass Solution {\n\n public int minFlipsMonoIncr(String s) {\n int ones = 0, flips = 0;\n for(char c: s.toCharArray()) {\n if (c | darian-catalin-cucer | NORMAL | 2022-04-22T18:52:13.093258+00:00 | 2022-04-22T18:52:13.093306+00:00 | 316 | false | \n\tclass Solution {\n\n public int minFlipsMonoIncr(String s) {\n int ones = 0, flips = 0;\n for(char c: s.toCharArray()) {\n if (c == \'1\') {\n ones++;\n } else {\n flips = Math.min(ones, flips + 1);\n }\n }\n return flips;... | 4 | 0 | ['Java'] | 0 |
flip-string-to-monotone-increasing | Python simple | python-simple-by-ploypaphat-ukn3 | Keep track of zero and one. Since this is an increasing, the left side would likely be \'zero\', hence while iterating through the string, all the leading zero( | ploypaphat | NORMAL | 2022-03-27T23:27:35.827217+00:00 | 2022-04-03T02:10:48.285234+00:00 | 403 | false | Keep track of zero and one. Since this is an increasing, the left side would likely be \'zero\', hence while iterating through the string, all the leading zero(s) will be ignored (set count_zero to count_one, which is zero because we have not hit any \'one\' yet). Once we starts hitting \'one\', then the logic will com... | 4 | 0 | ['Python', 'Python3'] | 0 |
flip-string-to-monotone-increasing | C++||Recursion+Memoization|| | crecursionmemoization-by-rohitsharma8-85eq | \n vector<vector<int>>dp;\n int util(string&s,int i,bool flag){\n if(i>=s.size())\n return 0;\n if(dp[i][int(flag)]!=-1)\n | rohitsharma8 | NORMAL | 2022-03-24T09:04:33.337801+00:00 | 2022-03-24T09:13:29.448618+00:00 | 433 | false | ```\n vector<vector<int>>dp;\n int util(string&s,int i,bool flag){\n if(i>=s.size())\n return 0;\n if(dp[i][int(flag)]!=-1)\n return dp[i][int(flag)];\n if(s[i]==\'0\' and flag){//if we already come across 1 and now "i" is at 0 then we have to flip it\n return... | 4 | 0 | ['Recursion', 'Memoization', 'C'] | 1 |
flip-string-to-monotone-increasing | C++ | Detailed Explanation | Time O(N) | Space O(1) | c-detailed-explanation-time-on-space-o1-nm34i | Let\'s understand by an example:\nSuppose,\ns = "101"\nn = s.length() = 3\n\nPossible monotonic sequences for a string of length 3 are:\n\n\t"000"\n\t"001"\n\t" | joshiatharva | NORMAL | 2021-11-08T06:08:01.255548+00:00 | 2021-11-08T06:19:10.634393+00:00 | 311 | false | Let\'s understand by an example:\nSuppose,\n`s = "101"`\n`n = s.length() = 3`\n\nPossible monotonic sequences for a string of length 3 are:\n```\n\t"000"\n\t"001"\n\t"011"\n\t"111"\n```\n\t\nWe will achieve minimum flips by converting given string "s" to one of these possible monotonic sequences. But, at the moment we ... | 4 | 0 | ['C'] | 0 |
flip-string-to-monotone-increasing | [Python 3] Single pass without extra memory | python-3-single-pass-without-extra-memor-4sd1 | \nclass Solution(object):\n def minFlipsMonoIncr(self, s):\n ones = 0\n flips = 0\n \n for c in s:\n if c == \'0\'and | abstractart | NORMAL | 2021-09-16T06:06:18.110811+00:00 | 2021-11-28T09:10:09.197904+00:00 | 352 | false | ```\nclass Solution(object):\n def minFlipsMonoIncr(self, s):\n ones = 0\n flips = 0\n \n for c in s:\n if c == \'0\'and ones > 0:\n flips += 1\n ones -= 1\n elif c == \'1\':\n ones += 1\n \n return flips\n``... | 4 | 0 | ['Python', 'Python3'] | 2 |
flip-string-to-monotone-increasing | C++ RECURSIVE,DP O(N)|O(1) Auxiliary space sol | c-recursivedp-ono1-auxiliary-space-sol-b-kozu | 1.Recursive solution\nThe recursive idea is taking the last character of the string.We can have two cases:-\n##### 1)If s[last]==\'1\' \nIn this case we can sim | jayadeepbose18 | NORMAL | 2021-08-11T05:19:59.267149+00:00 | 2022-01-18T14:43:56.434448+00:00 | 125 | false | **1.Recursive solution**\nThe recursive idea is taking the last character of the string.We can have two cases:-\n##### 1)*If s[last]==\'1\'* \nIn this case we can simply ignore the character and move on to the previous character.Bcoz this doesnt effect the monotonicty.\n**f(s,l)=f(s,l-1);**\n##### 2)*If s[last]==\'0\'*... | 4 | 0 | [] | 0 |
flip-string-to-monotone-increasing | Easy Solution , detailed explanation (with eg) | easy-solution-detailed-explanation-with-e66zz | class Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n /\n\t\t\n ans can be either flip all 1 to 0 000000000 | nish2447 | NORMAL | 2021-08-10T10:11:59.086840+00:00 | 2021-08-10T10:18:22.188896+00:00 | 194 | false | class Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n /*\n\t\t\n ans can be either flip all 1 to 0 000000000000\n\t or flip all 0 to one 111111111111\n or traverse and find the terms to be flipped 0010... | 4 | 0 | [] | 1 |
flip-string-to-monotone-increasing | C++ one-pass DP in 4 lines | c-one-pass-dp-in-4-lines-by-mrsuyi-cho6 | d0: minimum moves to flip S[0, i) to array of all \'0\'.\nd1: minimum moves to flip S[0, i) to array with some \'0\' in front and some \'1\' (possibly none) in | mrsuyi | NORMAL | 2020-04-16T17:49:05.435508+00:00 | 2020-04-16T17:49:05.435559+00:00 | 446 | false | d0: minimum moves to flip S[0, i) to array of all \'0\'.\nd1: minimum moves to flip S[0, i) to array with some \'0\' in front and some \'1\' (possibly none) in back.\n```\nclass Solution {\npublic:\n int minFlipsMonoIncr(string S) {\n int d0 = 0, d1 = 0;\n for (int i = 0; i < S.size(); ++i)\n ... | 4 | 0 | ['Dynamic Programming', 'C'] | 1 |
flip-string-to-monotone-increasing | DP | Explain | Recursion | Simple | CPP | OnePass | dp-explain-recursion-simple-cpp-onepass-w3hrf | Calculating the number of fllips required till current position \'i\':\n\nKeep maintaining count of number of one\'s till current index, in some variable say "o | nitishal | NORMAL | 2020-04-15T13:11:32.137138+00:00 | 2020-04-15T13:17:28.838696+00:00 | 300 | false | **Calculating the number of fllips required till current position \'i\':**\n\nKeep maintaining count of number of one\'s till current index, in some variable say "one", \nNow the problem at hand can be split into following two cases :\n* **If current index value is one \'1\' :**\n\t1. Increment the count of ones "one"\... | 4 | 0 | [] | 1 |
flip-string-to-monotone-increasing | javascript beat 100% | javascript-beat-100-by-huihancarl188-atcj | \nvar minFlipsMonoIncr = function(S) {\n let cur = 0;\n for(let i = 0 ; i < S.length; i++) {\n if(S.charAt(i) === \'0\') {\n // first fl | huihancarl188 | NORMAL | 2019-05-17T04:52:54.314566+00:00 | 2019-05-17T04:52:54.314596+00:00 | 248 | false | ```\nvar minFlipsMonoIncr = function(S) {\n let cur = 0;\n for(let i = 0 ; i < S.length; i++) {\n if(S.charAt(i) === \'0\') {\n // first flip all 0 into 1;\n cur++;\n }\n }\n let res = cur;\n for(let i = 0 ; i < S.length; i++) {\n if(S.charAt(i) === \'0\') {\n ... | 4 | 0 | [] | 0 |
flip-string-to-monotone-increasing | Clean DP Python - O(n)/O(1) | clean-dp-python-ono1-by-wxy9018-6951 | for each position, we will rember the cost for maintaining an array that ends with \'0\' and ends with \'1\'\n\n\n\'\'\'\nclass Solution:\n def minFlipsMonoI | wxy9018 | NORMAL | 2019-04-25T03:25:13.005419+00:00 | 2019-04-25T03:25:13.005490+00:00 | 274 | false | for each position, we will rember the cost for maintaining an array that ends with \'0\' and ends with \'1\'\n\n```\n\'\'\'\nclass Solution:\n def minFlipsMonoIncr(self, S: str) -> int:\n dp0, dp1 = 0, 0 # dp0: maintain a all-0 array; dp1: maintain an array that end with 1\n for c in S:\n if... | 4 | 0 | [] | 0 |
flip-string-to-monotone-increasing | O(n) Java with O(1) space with Intuitive Explanation | on-java-with-o1-space-with-intuitive-exp-czkq | The basic idea is to travel from left to right. At every step i:\n(1) flip every 1 to the left of i(including) to 0\n(2) flip every 0 to the right of i(excludin | yuanb10 | NORMAL | 2018-10-21T03:12:31.990857+00:00 | 2018-10-21T16:26:01.418348+00:00 | 918 | false | The basic idea is to travel from left to right. At every step i:\n(1) flip every 1 to the left of i(including) to 0\n(2) flip every 0 to the right of i(excluding) to 1\nFind the minimum along the way.\n\n```\nclass Solution {\n public int minFlipsMonoIncr(String S) {\n int r0 = 0, l1 = 0;\n \n f... | 4 | 0 | [] | 3 |
flip-string-to-monotone-increasing | PREFIX 1's & SUFFIX 0's || C++ | prefix-1s-suffix-0s-c-by-ganeshkumawat87-9wyj | Code\n\nclass Solution {\npublic:\n int minFlipsMonoIncr(string str) {\n int n = str.length(),i;\n vector<int> p(n,0),s(n,0);\n p[0] = ( | ganeshkumawat8740 | NORMAL | 2023-06-22T03:48:19.848801+00:00 | 2023-06-22T03:48:19.848827+00:00 | 328 | false | # Code\n```\nclass Solution {\npublic:\n int minFlipsMonoIncr(string str) {\n int n = str.length(),i;\n vector<int> p(n,0),s(n,0);\n p[0] = (str[0]==\'1\');\n for(i = 1; i < n; i++){\n if(str[i]==\'1\'){\n p[i] = p[i-1]+1;\n }else{\n p[i... | 3 | 0 | ['String', 'Dynamic Programming', 'C++'] | 0 |
flip-string-to-monotone-increasing | Explanation in laymens terms [Easy to understand] | explanation-in-laymens-terms-easy-to-und-n8a5 | Intuition\nBasically the idea is that once we reach a \'1\' we will start flipping \'0\'s to 1s until the count for zeros is less than ones but as an when the c | darkmatter404 | NORMAL | 2023-01-17T21:20:57.580255+00:00 | 2023-01-17T21:40:36.802960+00:00 | 320 | false | # Intuition\nBasically the idea is that once we reach a \'1\' we will start flipping \'0\'s to 1s until the count for zeros is less than ones but as an when the count for zero increases more than that of ones as we are logically supposed to flip the 1s instead of zeroes. \n\nThe way we will be able to acheive this is b... | 3 | 0 | ['Python', 'C++', 'Java', 'Python3', 'C#'] | 2 |
flip-string-to-monotone-increasing | Simple solution without DP | simple-solution-without-dp-by-aadarshpnd-2ah3 | Intuition\nNo need to think much, stand at any index, count number of 1s to the left of it, count numbr of 0s as flips. At the end, u either have to replace 1s | aadarshpndey | NORMAL | 2023-01-17T17:50:08.912748+00:00 | 2023-01-17T17:50:08.912804+00:00 | 22 | false | # Intuition\nNo need to think much, stand at any index, count number of 1s to the left of it, count numbr of 0s as flips. At the end, u either have to replace 1s with 0 or otherwise. Store the min of them as ur ans(flips). \n\nThis que is tagged as DP only bcoz its updating ans at a particular state using previous stat... | 3 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | intuitive way to solve| TC-O(n) and SC-O(1). | intuitive-way-to-solve-tc-on-and-sc-o1-b-w5gv | \n# Code\n\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s)\n {\n int cnt_flip = 0, cnt_one = 0;\n for (auto i : s)\n { \n | divyam_04 | NORMAL | 2023-01-17T11:01:55.460389+00:00 | 2023-01-17T11:01:55.460436+00:00 | 26 | false | \n# Code\n```\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s)\n {\n int cnt_flip = 0, cnt_one = 0;\n for (auto i : s)\n { \n\n if (i == \'0\')\n cnt_flip++;\n else{\n cnt_one++; \n }\n cnt_flip = min(cnt... | 3 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | C++ O(N) Solution|| Simple Explanation with example | c-on-solution-simple-explanation-with-ex-89vg | Approach\n Describe your approach to solving the problem. \nFor monotone increasing string all the zeros are on the left side (possibly 0) and all the ones are | umangrathi110 | NORMAL | 2023-01-17T10:21:08.755595+00:00 | 2023-01-17T10:21:08.755640+00:00 | 24 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nFor monotone increasing string all the zeros are on the left side (possibly 0) and all the ones are on the right side(possibly 0). \n(000111 , 00000 , 11111 all are monotone increasing)\n1. So, all the zeroes occur before the first one are useless f... | 3 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | Easy Understanding Solution | JAVA | Beats 92% ✅✅ | easy-understanding-solution-java-beats-9-su06 | \n# Code\n\nclass Solution {\n public int minFlipsMonoIncr(String s) {\n\n //Initialization\n int flips=0,ones=0;\n\n //flipping zeros a | s147 | NORMAL | 2023-01-17T06:57:59.983782+00:00 | 2023-01-17T06:57:59.983833+00:00 | 78 | false | \n# Code\n```\nclass Solution {\n public int minFlipsMonoIncr(String s) {\n\n //Initialization\n int flips=0,ones=0;\n\n //flipping zeros and oes to get monotone\n for(int i=0;i<s.length();i++)\n {\n //checking character is \'0\'\n if(s.charAt(i)==\'0\')\n ... | 3 | 0 | ['Java'] | 0 |
flip-string-to-monotone-increasing | ✅Accepted| | ✅Easy solution || ✅Short & Simple || ✅Best Method | accepted-easy-solution-short-simple-best-hqr8 | \n# Code\n\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n int n = s.size();\n int one_counts = 0;\n int dp = 0;\n | sanjaydwk8 | NORMAL | 2023-01-17T06:17:06.912817+00:00 | 2023-01-17T06:17:06.912922+00:00 | 27 | false | \n# Code\n```\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n int n = s.size();\n int one_counts = 0;\n int dp = 0;\n for(int i = 1; i <= n; i++) {\n if(s[i - 1] == \'1\')\n one_counts++;\n else\n dp = min(dp + 1, one_cou... | 3 | 0 | ['C++'] | 0 |
flip-string-to-monotone-increasing | Easiest Approach || Dynamic Programming | easiest-approach-dynamic-programming-by-kgzty | 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 | ankiit_k_ | NORMAL | 2023-01-17T05:15:05.670421+00:00 | 2023-01-17T05:15:05.670452+00:00 | 25 | false | # 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 | 0 | ['Dynamic Programming', 'C++'] | 1 |
flip-string-to-monotone-increasing | ✅ [Java/C++] 100% Solution using Dynamic Programming (Flip String to Monotone Increasing) | javac-100-solution-using-dynamic-program-9etq | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | arnavsharma2711 | NORMAL | 2023-01-17T05:11:01.508505+00:00 | 2023-01-17T05:11:01.508538+00:00 | 175 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```Java []\nclass Solution {\n public int minFlipsMonoIncr(String s) {\n int countOne = 0, countFlip = 0; \n ... | 3 | 0 | ['String', 'Dynamic Programming', 'C++', 'Java'] | 0 |
flip-string-to-monotone-increasing | python, dynamic programming, 5 lines of code | python-dynamic-programming-5-lines-of-co-2y2o | ERROR: type should be string, got "https://leetcode.com/submissions/detail/879635531/ \\nRuntime: 187 ms, faster than 84.62% of Python3 online submissions for Flip String to Monotone Increasing. " | nov05 | NORMAL | 2023-01-17T03:55:35.229155+00:00 | 2023-01-24T17:02:06.582761+00:00 | 59 | false | ERROR: type should be string, got "https://leetcode.com/submissions/detail/879635531/ \\nRuntime: **187 ms**, faster than 84.62% of Python3 online submissions for Flip String to Monotone Increasing. \\nMemory Usage: 14.9 MB, less than 72.76% of Python3 online submissions for Flip String to Monotone Increasing. \\n```\\nclass Solution:\\n def minFlipsMonoIncr(self, s: str) -> int:\\n minFlips = n = s.count(\\'0\\') ## flip to all \\'1\\'s\\n for c in s: ## flip to one \"0\", two \"0\"s, three \"0\"s...\\n n += 1 if c==\\'1\\' else -1\\n minFlips = min(minFlips, n)\\n return minFlips\\n```\\n**A large test case** \\nhttps://leetcode.com/submissions/detail/879579954/testcase/" | 3 | 0 | ['Dynamic Programming', 'Python'] | 0 |
flip-string-to-monotone-increasing | Day 17 || O(N) Time and O(1) space || Easiest DP Logic Based Solution | day-17-on-time-and-o1-space-easiest-dp-l-6p94 | \nIf my solution is helpful to you then please upvote me.\n# Intuition\n1. If s[i - 1] = \'1\', then we have dp[i] = dp[i - 1], since we can always append a cha | singhabhinash | NORMAL | 2023-01-17T02:50:18.625324+00:00 | 2023-01-17T04:24:32.374992+00:00 | 222 | false | \n**If my solution is helpful to you then please upvote me.**\n# Intuition\n1. If s[i - 1] = \'1\', then we have dp[i] = dp[i - 1], since we can always append a character \'1\' to the end of a monotone ... | 3 | 0 | ['Dynamic Programming', 'C++'] | 1 |
flip-string-to-monotone-increasing | 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 | 𝗦𝗶𝗺𝗽𝗹𝗲 𝗩𝗶𝗱𝗲𝗼 𝗦𝗼𝗹𝘂𝘁𝗶𝗼𝗻 | DP | javascript-simple-video-solution-dp-by-m-mh04 | Intuition & Approach\n Describe your approach to solving the problem. \n\uD835\uDDD7\uD835\uDDF2\uD835\uDE01\uD835\uDDEE\uD835\uDDF6\uD835\uDDF9\uD835\uDDF2\uD | monuchaudhary1 | NORMAL | 2023-01-17T02:44:30.087665+00:00 | 2023-01-17T02:44:30.087711+00:00 | 418 | false | # Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\n\uD835\uDDD7\uD835\uDDF2\uD835\uDE01\uD835\uDDEE\uD835\uDDF6\uD835\uDDF9\uD835\uDDF2\uD835\uDDF1 \uD835\uDDD4\uD835\uDDFD\uD835\uDDFD\uD835\uDDFF\uD835\uDDFC\uD835\uDDEE\uD835\uDDF0\uD835\uDDF5 \uD835\uDDD8\uD835\uDE05\uD835\uDDFD\uD835\u... | 3 | 0 | ['Dynamic Programming', 'JavaScript'] | 2 |
flip-string-to-monotone-increasing | Easy to understand - Intuitive DP using recursion | easy-to-understand-intuitive-dp-using-re-s8pn | https://github.com/Freeze777/SDE-Interviewer-Notes/blob/main/LeetCodeKotlin/src/main/kotlin/leetcode/medium/dp/FlipStringMonotoneIncrease.kt | freeze_francis | NORMAL | 2023-01-17T01:29:34.291240+00:00 | 2023-01-17T01:29:34.291281+00:00 | 611 | false | https://github.com/Freeze777/SDE-Interviewer-Notes/blob/main/LeetCodeKotlin/src/main/kotlin/leetcode/medium/dp/FlipStringMonotoneIncrease.kt | 3 | 0 | ['Kotlin'] | 0 |
flip-string-to-monotone-increasing | Python3 || 79 ms, faster than 100.00% of Python3 || Clean and Easy to Understand | python3-79-ms-faster-than-10000-of-pytho-e1zy | \ndef minFlipsMonoIncr(self, s: str) -> int:\n result = 0\n ones = 0\n for num in s:\n if num ==\'1\':\n ones += | harshithdshetty | NORMAL | 2023-01-17T01:22:14.168981+00:00 | 2023-01-17T01:22:14.169028+00:00 | 195 | false | ```\ndef minFlipsMonoIncr(self, s: str) -> int:\n result = 0\n ones = 0\n for num in s:\n if num ==\'1\':\n ones += 1\n else:\n result += 1\n if result > ones:\n result = ones \n return r... | 3 | 1 | ['Dynamic Programming', 'Prefix Sum', 'Python', 'Python3'] | 0 |
roman-to-integer | ✅Best Method || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | best-method-c-java-python-beginner-frien-pmoe | 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# Int | rahulvarma5297 | NORMAL | 2023-06-18T08:25:56.677662+00:00 | 2023-06-26T09:36:55.834340+00:00 | 566,677 | false | **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... | 3,188 | 9 | ['Hash Table', 'Math', 'C++', 'Java', 'Python3'] | 122 |
roman-to-integer | Clean Python, beats 99.78%. | clean-python-beats-9978-by-hgrsd-axkt | The Romans would most likely be angered by how it butchers their numeric system. Sorry guys.\n\nPython\nclass Solution:\n def romanToInt(self, s: str) -> int | hgrsd | NORMAL | 2019-03-29T20:58:38.986386+00:00 | 2019-03-29T20:58:38.986426+00:00 | 242,494 | false | 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... | 2,330 | 10 | ['Python', 'Python3'] | 291 |
roman-to-integer | java 90% faster solution | java-90-faster-solution-by-sd98754-re1o | \n public int romanToInt(String s) {\n int ans = 0, num = 0;\n for (int i = s.length()-1; i >= 0; i--) {\n switch(s.charAt(i)) {\n | sd98754 | NORMAL | 2022-09-27T22:03:31.255244+00:00 | 2022-09-27T22:03:31.255283+00:00 | 270,451 | false | ```\n public int romanToInt(String s) {\n int ans = 0, num = 0;\n for (int i = s.length()-1; i >= 0; i--) {\n switch(s.charAt(i)) {\n case \'I\': num = 1; break;\n case \'V\': num = 5; break;\n case \'X\': num = 10; break;\n case \'L\... | 1,181 | 1 | ['Java'] | 76 |
roman-to-integer | My Straightforward Python Solution | my-straightforward-python-solution-by-we-qxzz | \n class Solution:\n # @param {string} s\n # @return {integer}\n def romanToInt(self, s):\n roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X' | wenfengqiu | NORMAL | 2015-06-25T20:20:14+00:00 | 2018-10-26T00:54:16.503090+00:00 | 109,705 | false | \n class Solution:\n # @param {string} s\n # @return {integer}\n def romanToInt(self, s):\n roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1}\n z = 0\n for i in range(0, len(s) - 1):\n if roman[s[i]] < roman[s[i+1]]:\n z -= roman[s[i]]\n ... | 723 | 5 | [] | 49 |
roman-to-integer | 【Video】Looping two characters at a time. | video-looping-two-characters-at-a-time-b-squ4 | Intuition\nLooping two characters at a time.\n\n# Solution Video\n\nhttps://youtu.be/yUYp0LlVXH4\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to m | niits | NORMAL | 2024-09-29T15:35:29.663498+00:00 | 2024-11-29T13:11:19.369139+00:00 | 78,729 | false | # Intuition\nLooping two characters at a time.\n\n# Solution Video\n\nhttps://youtu.be/yUYp0LlVXH4\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\nSubscribers: 9,... | 702 | 0 | ['Hash Table', 'String', 'C++', 'Java', 'Python3', 'JavaScript'] | 14 |
roman-to-integer | Clean O(n) c++ solution | clean-on-c-solution-by-wsugrad77-53hk | Problem is simpler to solve by working the string from back to front and using a map. Runtime speed is 88 ms.\n\n\n\n int romanToInt(string s) \n {\n | wsugrad77 | NORMAL | 2015-01-23T03:32:10+00:00 | 2018-10-22T13:36:56.935703+00:00 | 136,002 | false | Problem is simpler to solve by working the string from back to front and using a map. Runtime speed is 88 ms.\n\n\n\n int romanToInt(string s) \n {\n unordered_map<char, int> T = { { 'I' , 1 },\n { 'V' , 5 },\n { 'X' , 10 },\n ... | 677 | 7 | [] | 68 |
roman-to-integer | Easy C++ solution with short code | easy-c-solution-with-short-code-by-jeeta-nro5 | \n# Approach\nIf there are Numbers such as XL, IV, etc. \nSimply subtract the smaller number and add the larger number in next step. \nFor example, if there is | Jeetaksh | NORMAL | 2023-01-14T17:26:29.362602+00:00 | 2023-01-15T06:50:37.303305+00:00 | 119,430 | false | \n# Approach\nIf there are Numbers such as XL, IV, etc. \nSimply subtract the smaller number and add the larger number in next step. \nFor example, if there is XL, ans =-10 in first step, ans=-10+50=40 in next step.\n\nOtherwise, just add the numbers. \n<!-- Describe your approach to solving the problem. -->\n\n# Compl... | 447 | 1 | ['C++'] | 18 |
roman-to-integer | 7ms solution in Java. easy to understand | 7ms-solution-in-java-easy-to-understand-zul35 | public int romanToInt(String s) {\n int nums[]=new int[s.length()];\n for(int i=0;i<s.length();i++){\n switch (s.charAt(i)){\n | yangneu2015 | NORMAL | 2015-10-31T00:34:12+00:00 | 2018-10-21T22:33:37.060446+00:00 | 106,144 | false | public int romanToInt(String s) {\n int nums[]=new int[s.length()];\n for(int i=0;i<s.length();i++){\n switch (s.charAt(i)){\n case 'M':\n nums[i]=1000;\n break;\n case 'D':\n nums[i]=500;\n ... | 425 | 2 | [] | 56 |
roman-to-integer | 🔥 Python || Easily Understood ✅ || Faster than 98% || Less than 76% || O(n) | python-easily-understood-faster-than-98-gcdnn | Code:\n\nclass Solution:\n def romanToInt(self, s: str) -> int:\n roman_to_integer = {\n \'I\': 1,\n \'V\': 5,\n \'X\ | wingskh | NORMAL | 2022-08-15T10:51:54.609226+00:00 | 2022-08-15T10:51:54.609270+00:00 | 130,440 | false | 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... | 412 | 1 | ['Python', 'Python3'] | 54 |
roman-to-integer | My solution for this question but I don't know is there any easier way? | my-solution-for-this-question-but-i-dont-s7ic | count every Symbol and add its value to the sum, and minus the extra part of special cases. \n\n public int romanToInt(String s) {\n int sum=0;\n | hongbin2 | NORMAL | 2014-01-26T05:53:45+00:00 | 2018-10-24T18:26:52.487861+00:00 | 173,255 | false | count every Symbol and add its value to the sum, and minus the extra part of special cases. \n\n public int romanToInt(String s) {\n int sum=0;\n if(s.indexOf("IV")!=-1){sum-=2;}\n if(s.indexOf("IX")!=-1){sum-=2;}\n if(s.indexOf("XL")!=-1){sum-=20;}\n if(s.indexOf("XC")!=-1){sum-=... | 410 | 20 | [] | 111 |
roman-to-integer | Hash Table Concept Python3 | hash-table-concept-python3-by-ganjinavee-uvmm | \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 | GANJINAVEEN | NORMAL | 2023-04-16T03:53:56.762583+00:00 | 2023-04-16T03:53:56.762632+00:00 | 79,928 | false | \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 ... | 403 | 0 | ['Python3'] | 26 |
roman-to-integer | [C++] ✅ || O(n) || Short Code 🔥 || Clean code || fast and easy | c-on-short-code-clean-code-fast-and-easy-ouyj | Intuitive\nRoman numerals are usually written largest to smallest from left to right, for example: XII (7), XXVII (27), III (3)...\nIf a small value is placed b | hoshang2900 | NORMAL | 2022-08-15T00:04:28.367892+00:00 | 2023-03-12T09:37:32.486373+00:00 | 65,394 | false | **Intuitive**\nRoman numerals are usually written largest to smallest from left to right, for example: XII (7), XXVII (27), III (3)...\nIf a small value is placed before a bigger value then it\'s a combine number, for exampe: IV (4), IX (9), XIV (14)...\nIV = -1 + 5\nVI = 5 + 1\nXL = -10 + 50\nLX = 50 + 10\nSo, if a sm... | 370 | 5 | ['C'] | 26 |
roman-to-integer | JS | Hash Table | With exlanation | js-hash-table-with-exlanation-by-karina_-16lt | To solve this problem, we need to create a hash table, the characters in which will correspond to a certain number. Passing along the line, we will check the cu | Karina_Olenina | NORMAL | 2022-10-15T17:05:42.231625+00:00 | 2022-10-20T12:38:19.879082+00:00 | 54,381 | false | To solve this problem, we need to create a hash table, the characters in which will correspond to a certain number. Passing along the line, we will check the current and the next character at once, if the current one is greater than the next one, then everything is fine, we add it to the result (it is initially equal t... | 347 | 0 | ['Hash Table', 'Ordered Set', 'JavaScript'] | 60 |
roman-to-integer | Simple JavaScript Solution Easy Understanding | simple-javascript-solution-easy-understa-uxop | \nsymbols = {\n "I": 1,\n "V": 5,\n "X": 10,\n "L": 50,\n "C": 100,\n "D": 500,\n "M": 1000\n};\n\nvar romanToInt = function(s) {\n valu | garyguan0713 | NORMAL | 2019-07-03T17:49:00.961763+00:00 | 2019-07-03T17:49:00.961804+00:00 | 39,622 | false | ```\nsymbols = {\n "I": 1,\n "V": 5,\n "X": 10,\n "L": 50,\n "C": 100,\n "D": 500,\n "M": 1000\n};\n\nvar romanToInt = function(s) {\n value = 0;\n for(let i = 0; i < s.length; i+=1){\n symbols[s[i]] < symbols[s[i+1]] ? value -= symbols[s[i]]: value += symbols[s[i]]\n }\n return ... | 338 | 1 | ['JavaScript'] | 30 |
roman-to-integer | 4 lines in Python | 4-lines-in-python-by-agave-dywz | d = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1}\n \n def romanToInt(self, s):\n res, p = 0, 'I'\n for c in s[::-1]:\n | agave | NORMAL | 2016-06-04T03:44:43+00:00 | 2018-10-06T23:14:27.296354+00:00 | 33,490 | false | d = {'M':1000, 'D':500, 'C':100, 'L':50, 'X':10, 'V':5, 'I':1}\n \n def romanToInt(self, s):\n res, p = 0, 'I'\n for c in s[::-1]:\n res, p = res - d[c] if d[c] < d[p] else res + d[c], c\n return res | 195 | 2 | [] | 31 |
roman-to-integer | JAVA----------------Easy Version To Understand!!!! | java-easy-version-to-understand-by-hello-ak0n | \tpublic static int romanToInt(String s) {\n\t\tif (s == null || s.length() == 0)\n\t\t\treturn -1;\n\t\tHashMap<Character, Integer> map = new HashMap<Character | helloworld123456 | NORMAL | 2016-01-01T02:40:23+00:00 | 2018-10-14T20:29:16.666415+00:00 | 34,238 | false | \tpublic static int romanToInt(String s) {\n\t\tif (s == null || s.length() == 0)\n\t\t\treturn -1;\n\t\tHashMap<Character, Integer> map = new HashMap<Character, Integer>();\n\t\tmap.put('I', 1);\n\t\tmap.put('V', 5);\n\t\tmap.put('X', 10);\n\t\tmap.put('L', 50);\n\t\tmap.put('C', 100);\n\t\tmap.put('D', 500);\n\t\... | 184 | 1 | [] | 24 |
roman-to-integer | Python Beginner [98% fast 100% Memo] | python-beginner-98-fast-100-memo-by-dxbk-slag | \ndef romanToInt(self, s: str) -> int:\n\tres, prev = 0, 0\n\tdict = {\'I\':1, \'V\':5, \'X\':10, \'L\':50, \'C\':100, \'D\':500, \'M\':1000}\n\tfor i in s[::-1 | dxbking | NORMAL | 2019-12-13T06:03:44.512362+00:00 | 2019-12-13T06:03:44.512414+00:00 | 19,354 | false | ```\ndef romanToInt(self, s: str) -> int:\n\tres, prev = 0, 0\n\tdict = {\'I\':1, \'V\':5, \'X\':10, \'L\':50, \'C\':100, \'D\':500, \'M\':1000}\n\tfor i in s[::-1]: # rev the s\n\t\tif dict[i] >= prev:\n\t\t\tres += dict[i] # sum the value iff previous value same or more\n\t\telse:\n\t\t\tres -= dict[i] ... | 156 | 1 | ['Python', 'Python3'] | 13 |
roman-to-integer | 💻✅BEATS 100%⌛⚡[C++/Java/Py3/JS]🍨| EASY n CLEAN EXPLANATION⭕💌 | beats-100cjavapy3js-easy-n-clean-explana-l3c8 | IntuitionRoman numerals use specific rules:
If a smaller numeral comes before a larger one, it is subtracted (e.g., IV = 4).
Otherwise, the values are added (e. | Fawz-Haaroon | NORMAL | 2025-01-26T22:46:14.216333+00:00 | 2025-01-26T22:46:14.216333+00:00 | 31,985 | false | # Intuition
Roman numerals use specific rules:
- If a smaller numeral comes before a larger one, it is subtracted (e.g., `IV = 4`).
- Otherwise, the values are added (e.g., `VI = 6`).
We can traverse the string, compare each numeral with the next, and decide whether to add or subtract.
# Approach
1. Create a helper fu... | 137 | 2 | ['C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 9 |
roman-to-integer | ✅ [C] || 100% Hashtable Solution || O(n) | c-100-hashtable-solution-on-by-bezlant-bieo | \nint romanToInt(char * s)\n{\n int t[\'X\' + 1] = {\n [\'I\'] = 1,\n [\'V\'] = 5,\n [\'X\'] = 10,\n [\'L\'] = 50,\n [\'C\ | bezlant | NORMAL | 2022-04-18T13:53:15.808297+00:00 | 2022-04-18T13:54:28.982948+00:00 | 10,810 | false | ```\nint romanToInt(char * s)\n{\n int t[\'X\' + 1] = {\n [\'I\'] = 1,\n [\'V\'] = 5,\n [\'X\'] = 10,\n [\'L\'] = 50,\n [\'C\'] = 100,\n [\'D\'] = 500,\n [\'M\'] = 1000,\n };\n int res = 0;\n for (int i = 0; s[i]; i++) {\n if (t[s[i]] < t[s[i+1]])\n ... | 116 | 0 | ['C'] | 13 |
roman-to-integer | Nice and clean TS/JS | nice-and-clean-tsjs-by-pirastrino-lt5z | You don\'t need to map CM, XC, "IX", "IV" separately. Eg.\nwhen you parse "MCMXCIV" to an array of integers you get:\n[1000, 100, 1000, 10, 100, 1, 5], if you a | pirastrino | NORMAL | 2022-06-04T11:16:21.716788+00:00 | 2022-06-04T13:19:17.200355+00:00 | 6,779 | false | You don\'t need to map `CM`, `XC`, `"IX"`, `"IV"` separately. Eg.\nwhen you parse `"MCMXCIV"` to an array of integers you get:\n`[1000, 100, 1000, 10, 100, 1, 5]`, if you add them together (from left to right),\nyou just need to check if next number is bigger, if so then you simply subtract\nthat number: `1000 - 100 + ... | 96 | 0 | ['TypeScript', 'JavaScript'] | 17 |
roman-to-integer | [C++] Concise Solution | c-concise-solution-by-kasracode-k4z1 | \nint romanToInt(string s) {\n\tunordered_map<char, int> mp = {{\'M\', 1000}, {\'D\', 500}, {\'C\', 100}, {\'L\', 50}, {\'X\', 10}, {\'V\', 5}, {\'I\', 1}};\n\t | KasraCode | NORMAL | 2019-06-23T00:31:16.737437+00:00 | 2019-06-23T00:31:50.076597+00:00 | 13,861 | false | ```\nint romanToInt(string s) {\n\tunordered_map<char, int> mp = {{\'M\', 1000}, {\'D\', 500}, {\'C\', 100}, {\'L\', 50}, {\'X\', 10}, {\'V\', 5}, {\'I\', 1}};\n\tint res = mp[s.back()];\n\tfor(int i = 0; i < s.size() - 1; i++) {\n\t\tif(mp[s[i]] < mp[s[i + 1]]) res -= mp[s[i]];\n\t\telse res += mp[s[i]];\n\t}\n\tretur... | 96 | 1 | ['C', 'C++'] | 10 |
roman-to-integer | ✅☑️ Best C++ Solution || Hash Table || Math || String || One Stop Solution. | best-c-solution-hash-table-math-string-o-1tbv | Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this problem using String + Hash Table + Math.\n\n# Approach\n Describe yo | its_vishal_7575 | NORMAL | 2023-02-18T18:21:49.038787+00:00 | 2023-02-18T19:27:38.304904+00:00 | 13,607 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this problem using String + Hash Table + Math.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can easily understand the approach by seeing the code which is easy to understand with comments.\n\n# C... | 88 | 0 | ['Hash Table', 'Math', 'String', 'C++'] | 4 |
roman-to-integer | Java efficient, easy to understand, with explaination | java-efficient-easy-to-understand-with-e-zq8u | First we use a hashmap to map the conversions of roman digits to integer.\nNow, if a numeral with smaller value precedes one with a larger value, we subtract th | shivamshah | NORMAL | 2020-04-14T17:31:20.885668+00:00 | 2020-04-14T17:31:20.885720+00:00 | 9,604 | false | First we use a hashmap to map the conversions of roman digits to integer.\nNow, if a numeral with smaller value precedes one with a larger value, we subtract the value from the total, otherwise we add the value to the total.\nAt the end, we still have to add the last character value.\n```\nclass Solution {\n public ... | 87 | 0 | ['Java'] | 4 |
roman-to-integer | ✅ [Accepted] Solution for Swift | accepted-solution-for-swift-by-asahiocea-ufj1 | \nDisclaimer: By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the cont | AsahiOcean | NORMAL | 2021-03-31T20:25:43.447934+00:00 | 2023-12-27T22:10:16.746363+00:00 | 8,991 | false | <blockquote>\n<b>Disclaimer:</b> By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the content freely and as you see fit. Any suggestions for improvement are welcome and greatly appreciated! Happy coding!\n</blockquote>\n\n```swift\... | 84 | 2 | ['Swift'] | 5 |
roman-to-integer | ✅🔥Beats 99.99% || 📈Easy solution with O(n) Approach ✔| C++ | Python | Java | Javascript | beats-9999-easy-solution-with-on-approac-rzlv | \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. | anshuP_cs24 | NORMAL | 2023-10-04T06:48:21.254011+00:00 | 2023-10-20T07:11:34.281842+00:00 | 15,726 | false | # \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... | 79 | 0 | ['Hash Table', 'Math', 'Two Pointers', 'String', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 9 |
roman-to-integer | Python simple solution | python-simple-solution-by-tovam-n98l | Python :\n\n\ndef romanToInt(self, s: str) -> int:\n\troman_dict = {\n\t\t\'I\' :1,\n\t\t\'V\' :5,\n\t\t\'X\' :10,\n\t\t\'L\' :50,\n\t\t\'C\' :100,\n\t\t\'D\' : | TovAm | NORMAL | 2021-10-30T22:20:35.389680+00:00 | 2021-10-30T22:20:35.389714+00:00 | 7,145 | false | **Python :**\n\n```\ndef romanToInt(self, s: str) -> int:\n\troman_dict = {\n\t\t\'I\' :1,\n\t\t\'V\' :5,\n\t\t\'X\' :10,\n\t\t\'L\' :50,\n\t\t\'C\' :100,\n\t\t\'D\' :500,\n\t\t\'M\' :1000\n\t}\n\n\ts = s.replace("IV", "IIII").replace("IX", "IIIIIIIII")\n\ts = s.replace("XL", "XXXX").replace("XC", "XXXXXXXXX")\n\ts = s... | 79 | 1 | ['Python', 'Python3'] | 12 |
roman-to-integer | C solution | c-solution-by-thedrafttin-29jj | Runtime: 12 ms, faster than 100.00% of C online submissions for Roman to Integer.\nMemory Usage: 7 MB, less than 100.00% of C online submissions for Roman to In | thedrafttin | NORMAL | 2019-04-09T15:12:34.161604+00:00 | 2019-04-09T15:12:34.161691+00:00 | 6,326 | false | Runtime: 12 ms, faster than 100.00% of C online submissions for Roman to Integer.\nMemory Usage: 7 MB, less than 100.00% of C online submissions for Roman to Integer\n```\nint romanToInt(char* s) {\n int value[100];\n value[\'I\'] = 1;\n value[\'V\'] = 5;\n value[\'X\'] = 10;\n value[\'L\'] = 50;\n va... | 69 | 2 | [] | 10 |
roman-to-integer | 0ms • 1LINER • 100% • Fastest Solution Explained • O(n) Time Complexity • O(n) Space Complexity | 0ms-1liner-100-fastest-solution-explaine-m9ia | 0ms \u2022 Beats 100% Time Complexity \u2022 Beats 100% Space Complexity\n\n### Kotlin\n\nclass Solution {\n fun romanToInt(s: String): Int {\n // 1. | darian-catalin-cucer | NORMAL | 2022-05-20T14:30:27.487958+00:00 | 2024-06-02T09:10:19.057092+00:00 | 15,750 | false | # 0ms \u2022 Beats 100% Time Complexity \u2022 Beats 100% Space Complexity\n\n### Kotlin\n```\nclass Solution {\n fun romanToInt(s: String): Int {\n // 1. Create a Map for Roman Numeral Values\n val translations = mapOf(\n "I" to 1,\n "V" to 5,\n "X" to 10,\n ... | 67 | 3 | ['Array', 'Hash Table', 'Math', 'String', 'Combinatorics', 'Python', 'C++', 'Java', 'Python3', 'Kotlin'] | 11 |
roman-to-integer | ⚠️Easiest 😎 FAANG Method Ever !!! 💥 | easiest-faang-method-ever-by-adityabhate-jtsg | \n# \uD83D\uDDEF\uFE0FComplexity :-\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity h | AdityaBhate | NORMAL | 2022-12-02T11:26:39.397719+00:00 | 2023-01-05T12:10:11.153469+00:00 | 18,385 | false | \n# \uD83D\uDDEF\uFE0FComplexity :-\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# \uD83D\uDDEF\uFE0FCode :-\n```\nclass Solution {\npublic:\n int romanToInt(string s) {\n int res=0;\n ... | 65 | 3 | ['Hash Table', 'Math', 'String', 'C++', 'Java'] | 21 |
roman-to-integer | JavaScript Clean Solution | javascript-clean-solution-by-control_the-w9hg | javascript\nvar romanToInt = function(s) {\n const map = { \'I\': 1, \'V\': 5, \'X\': 10, \'L\': 50, \'C\': 100, \'D\': 500, \'M\': 1000};\n let num = 0;\ | control_the_narrative | NORMAL | 2020-08-20T02:08:16.786358+00:00 | 2020-08-20T02:08:16.786407+00:00 | 6,365 | false | ```javascript\nvar romanToInt = function(s) {\n const map = { \'I\': 1, \'V\': 5, \'X\': 10, \'L\': 50, \'C\': 100, \'D\': 500, \'M\': 1000};\n let num = 0;\n \n for(let i = 0; i < s.length; i++) {\n const curr = map[s[i]], next = map[s[i+1]];\n if(curr < next) num -= curr;\n else num +... | 63 | 1 | ['JavaScript'] | 5 |
roman-to-integer | My easy-to-understand C++ solutions | my-easy-to-understand-c-solutions-by-xia-rr64 | class Solution {\n public:\n int romanToInt(string s) {\n int num = 0;\n int size = s.size();\n | xiaohui7 | NORMAL | 2014-12-17T16:30:21+00:00 | 2018-09-25T05:29:26.405360+00:00 | 11,598 | false | class Solution {\n public:\n int romanToInt(string s) {\n int num = 0;\n int size = s.size();\n \n for (int i = 0; i < size; i++) {\n \tif (i < (size - 1) && romanCharToInt(s[i]) < romanCharToInt(s[i + 1])) {\n ... | 57 | 1 | [] | 3 |
roman-to-integer | Very Simple Python Solution | very-simple-python-solution-by-user9872y-bsck | Intuition\n Describe your first thoughts on how to solve this problem. \nWe essentially start scanning adding all of the corresponding values for each character | user9872yq | NORMAL | 2023-01-07T22:15:43.895614+00:00 | 2023-01-07T22:15:43.895665+00:00 | 26,438 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe essentially start scanning adding all of the corresponding values for each character regardless of order. (e.g. "IX" is 11 not 9) Then, we check the order of the elements, and if we find that the order is reversed (i.e. "IX"), we make ... | 53 | 0 | ['Python3'] | 10 |
roman-to-integer | Easiest Beginner Friendly Sol || HashMap || C ++, Java, Python | easiest-beginner-friendly-sol-hashmap-c-koqgg | Intuition of this Problem:\nThe given code is implementing the conversion of a Roman numeral string into an integer. It uses an unordered map to store the mappi | singhabhinash | NORMAL | 2023-02-22T02:31:03.383970+00:00 | 2023-02-22T02:31:03.384013+00:00 | 13,934 | false | # Intuition of this Problem:\nThe given code is implementing the conversion of a Roman numeral string into an integer. It uses an unordered map to store the mapping between Roman numerals and their corresponding integer values. The algorithm takes advantage of the fact that in a valid Roman numeral string, the larger n... | 50 | 0 | ['Hash Table', 'Math', 'C++', 'Java', 'Python3'] | 4 |
roman-to-integer | Python | python-by-lividsu-5oi8 | Python\n\n rd = {\n "I" : 1,\n "V" : 5,\n "X" : 10,\n "L" : 50,\n "C" : 100,\n "D" : 50 | lividsu | NORMAL | 2020-12-09T09:09:06.022453+00:00 | 2020-12-09T09:09:06.022483+00:00 | 6,103 | false | Python\n```\n rd = {\n "I" : 1,\n "V" : 5,\n "X" : 10,\n "L" : 50,\n "C" : 100,\n "D" : 500,\n "M" : 1000\n }\n \n n = len(s)\n rt = 0\n for i in range(n):\n if i==n-1 or rd[s[i]] >= rd[s[i... | 50 | 1 | [] | 8 |
roman-to-integer | Python 3 -> Simple and detailed explanation | python-3-simple-and-detailed-explanation-3ux8 | Suggestions to make it better are always welcomed.\n\nFirst things first: Because we need to look up the value of each roman charater multiple times, let\'s sto | mybuddy29 | NORMAL | 2022-02-22T15:09:48.606565+00:00 | 2022-02-24T20:55:25.794610+00:00 | 2,350 | false | **Suggestions to make it better are always welcomed.**\n\nFirst things first: Because we need to look up the value of each roman charater multiple times, let\'s store them in a dictionary called sym to have O(1) lookup.\n\nExample:\nLooking at these characters is confusing. To come up with an algorithm, FIRST replace t... | 49 | 1 | ['Python3'] | 3 |
roman-to-integer | JavaScript Solution | javascript-solution-by-jeantimex-qtsc | javascript\nconst romanToInt = s => {\n if (!s || s.length === 0) {\n return 0;\n }\n\n const map = new Map([[\'I\', 1], [\'V\', 5], [\'X\', 10], [\'L\', | jeantimex | NORMAL | 2018-09-22T21:57:23.175267+00:00 | 2018-09-22T21:57:23.175306+00:00 | 6,440 | false | ```javascript\nconst romanToInt = s => {\n if (!s || s.length === 0) {\n return 0;\n }\n\n const map = new Map([[\'I\', 1], [\'V\', 5], [\'X\', 10], [\'L\', 50], [\'C\', 100], [\'D\', 500], [\'M\', 1000]]);\n\n let i = s.length - 1;\n let result = map.get(s[i]);\n\n while (i > 0) {\n const curr = map.get(s[... | 49 | 0 | [] | 5 |
roman-to-integer | Java Solution - Clean and Simple :) ( 7 ms ) | java-solution-clean-and-simple-7-ms-by-e-u7l2 | public int romanToInt(String str) {\n int[] a = new int[26];\n a['I' - 'A'] = 1;\n a['V' - 'A'] = 5;\n a['X' - 'A'] = 10;\n a | earlme | NORMAL | 2015-10-13T05:09:41+00:00 | 2018-08-28T01:30:03.210701+00:00 | 19,128 | false | public int romanToInt(String str) {\n int[] a = new int[26];\n a['I' - 'A'] = 1;\n a['V' - 'A'] = 5;\n a['X' - 'A'] = 10;\n a['L' - 'A'] = 50;\n a['C' - 'A'] = 100;\n a['D' - 'A'] = 500;\n a['M' - 'A'] = 1000;\n char prev = 'A';\n int sum = 0;\n ... | 49 | 6 | ['Java'] | 4 |
roman-to-integer | C# Runtime 94% and Memory 98% O(n) | c-runtime-94-and-memory-98-on-by-koliter-lqlr | This solution uses a switch case to reduce memory usage as well as a method scope currentValue Variable which enables the code to reuse the memory and thus dras | Koliter | NORMAL | 2021-07-25T19:47:11.529470+00:00 | 2022-11-04T13:22:28.336419+00:00 | 9,163 | false | This solution uses a switch case to reduce memory usage as well as a method scope `currentValue` Variable which enables the code to reuse the memory and thus drastically reduce memory usage. Simple for loop means solution is O(n), n being the length of the string.\n\nThe Results : \nRuntime: 80 ms, faster than 93.83% o... | 47 | 0 | ['C#'] | 8 |
roman-to-integer | PYTHON FASTEST SOLUTION | python-fastest-solution-by-coder_hash-6z69 | IV and VI both were being treated as 6. \nSimilarly IX and XI both were treated as 11.\n\nSo I put a condition whenever it encounters IV or IX then subtract 2\n | coder_hash | NORMAL | 2022-01-15T09:12:21.492140+00:00 | 2022-01-15T09:12:21.492180+00:00 | 2,146 | false | IV and VI both were being treated as 6. \nSimilarly IX and XI both were treated as 11.\n\nSo I put a condition whenever it encounters IV or IX then subtract 2\n\nSimilarily if XL or XC then subtract 20, \'CD\' or \'CM\' then subtract 200\n\nLike my logic? An upvote won\'t cost you anything ;)\n```\nclass Solution(objec... | 43 | 2 | ['Python'] | 3 |
roman-to-integer | Javascript | javascript-by-rbwn-p8ky | Runtime: 172 ms, faster than 48.97% of JavaScript online submissions for Roman to Integer.\nMemory Usage: 43.7 MB, less than 97.40% of JavaScript online submiss | rbwn | NORMAL | 2020-12-11T18:08:47.579002+00:00 | 2020-12-11T18:08:47.579036+00:00 | 8,436 | false | Runtime: 172 ms, faster than 48.97% of JavaScript online submissions for Roman to Integer.\nMemory Usage: 43.7 MB, less than 97.40% of JavaScript online submissions for Roman to Integer.\n\n```function romanToInt(s) {\n const legend = {\n I:1,\n V:5,\n X:10,\n L:50,\n C:100,\n D:500,\n M:1000\n }... | 43 | 0 | [] | 5 |
roman-to-integer | Easy C# Solution | easy-c-solution-by-erenyeagertatakae-kjk3 | We can parse the string from right to left and then subtract from grand total if the last value parsed is bigger than the current value.\n\n public int Roman | erenyeagertatakae | NORMAL | 2022-04-05T14:24:48.539893+00:00 | 2022-04-05T14:24:48.539937+00:00 | 8,007 | false | We can parse the string from right to left and then subtract from grand total if the last value parsed is bigger than the current value.\n```\n public int RomanToInt(string s) {\n var map = new Dictionary<char, int>();\n map.Add(\'I\', 1);\n map.Add(\'V\', 5);\n map.Add(\'X\',... | 42 | 0 | ['C#'] | 3 |
roman-to-integer | Golang solution (0ms) | golang-solution-0ms-by-klakovskiy-1d7r | To avoid many check I use var lv (last value) for define sign of current operations.\n\nRuntime: 0 ms, faster than 100.00% \nMemory Usage: 3 MB, less than 40.11 | klakovskiy | NORMAL | 2021-12-23T08:39:28.484107+00:00 | 2021-12-23T08:59:41.474161+00:00 | 6,448 | false | To avoid many check I use ```var lv``` (last value) for define sign of current operations.\n\nRuntime: 0 ms, faster than 100.00% \nMemory Usage: 3 MB, less than 40.11% (removing usages ```h,lv,cv``` variables doesn\'t help to improve memory usage)\n\n```\nfunc romanToInt(s string) int {\n\tvar v, lv, cv int\n\th := map... | 39 | 0 | ['Go'] | 9 |
roman-to-integer | Simple Python solution | simple-python-solution-by-lokeshsk1-4e78 | \nclass Solution:\n def romanToInt(self, s: str) -> int:\n r={\'I\':1,\'V\':5,\'X\':10,\'L\':50,\'C\':100,\'D\':500,\'M\':1000}\n tot=0\n | lokeshsk1 | NORMAL | 2020-07-20T10:04:25.847343+00:00 | 2021-01-04T11:52:24.939068+00:00 | 3,522 | false | ```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n r={\'I\':1,\'V\':5,\'X\':10,\'L\':50,\'C\':100,\'D\':500,\'M\':1000}\n tot=0\n for i in range(len(s)-1):\n if r[s[i]] < r[s[i+1]]:\n tot-=r[s[i]]\n else:\n tot+=r[s[i]]\n tot+... | 39 | 1 | ['Python', 'Python3'] | 2 |
roman-to-integer | [C++] Best Methods || Clean Code || Straightforward Solutions | c-best-methods-clean-code-straightforwar-m3s3 | Using ASCII equivalent of Roman numeralsThe implementation uses "Key" and "value" to map the Roman numeral characters to their corresponding integer values.The | nitishhsinghhh | NORMAL | 2023-03-22T09:56:37.031414+00:00 | 2025-01-29T09:03:38.718588+00:00 | 7,374 | false | # Using ASCII equivalent of Roman numerals
The implementation uses "Key" and "value" to map the Roman numeral characters to their corresponding integer values.
The code converts Roman numerals to integers. It iterates over the input string from right to left and uses the arrays to calculate the integer value of each... | 36 | 0 | ['Hash Table', 'Math', 'String', 'C++'] | 0 |
roman-to-integer | Java clean and fast solution | java-clean-and-fast-solution-by-qiyidk-b4ud | public int romanToInt(String s) {\n int num = 0;\n int l = s.length();\n int last = 1000;\n for (int i = 0; i < | qiyidk | NORMAL | 2016-01-11T05:23:46+00:00 | 2018-10-04T13:43:59.356961+00:00 | 10,645 | false | public int romanToInt(String s) {\n int num = 0;\n int l = s.length();\n int last = 1000;\n for (int i = 0; i < l; i++){\n int v = getValue(s.charAt(i));\n if (v > last) num = num - last * 2;\n num = num + v;\n ... | 35 | 1 | ['Java'] | 3 |
roman-to-integer | Python 3 solution less than 98% Memory Usage with explanation. | python-3-solution-less-than-98-memory-us-c5sf | Take one example:\nPre-calculate for "IV" which represent -2.\nNote: If you traversal from string, you will count "I", "V", "IV" => 5 + 1 + (-2) = 4.\nSo I put | wabesasa | NORMAL | 2022-04-13T04:38:33.444858+00:00 | 2022-04-13T04:39:16.604495+00:00 | 2,049 | false | Take one example:\nPre-calculate for "IV" which represent -2.\nNote: If you traversal from string, you will count "I", "V", "IV" => 5 + 1 + (-2) = 4.\nSo I put "IV" to -2.\n\n```\nclass Solution:\n def romanToInt(self, s: str) -> int:\n mapping = {\n "I": 1,\n "V": 5,\n "X": 1... | 34 | 0 | ['Python3'] | 2 |
roman-to-integer | [Rust] pattern matching without extra allocation | rust-pattern-matching-without-extra-allo-kjej | With only 2.3MiB memory usage and 100% ranking\n- Only use pattern guard expression (MatchArmGuard)\n\nrust\nimpl Solution {\n pub fn roman_to_int(s: String) | leetcodebot168 | NORMAL | 2019-09-04T14:42:08.516228+00:00 | 2019-09-04T14:51:23.972409+00:00 | 2,033 | false | - With only 2.3MiB memory usage and 100% ranking\n- Only use pattern guard expression (MatchArmGuard)\n\n```rust\nimpl Solution {\n pub fn roman_to_int(s: String) -> i32 {\n s.chars().rfold(0, |acc, c| {\n acc + match c {\n \'I\' if acc >= 5 => -1,\n \'I\' => 1,\n ... | 34 | 0 | ['Rust'] | 2 |
roman-to-integer | Simple java solution, 100% time | simple-java-solution-100-time-by-andreaz-twhh | \npublic int romanToInt(String s) {\n int n = 0;\n char prev = \' \';\n for (byte i = 0; i < s.length(); i++) {\n char c = s.cha | andreazube | NORMAL | 2019-04-24T23:49:32.379855+00:00 | 2019-04-24T23:49:32.379896+00:00 | 5,112 | false | ```\npublic int romanToInt(String s) {\n int n = 0;\n char prev = \' \';\n for (byte i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n n += getValue(c, prev);\n prev = c;\n }\n \n return n;\n }\n \n private int getValue(char c, ch... | 33 | 0 | ['Java'] | 5 |
roman-to-integer | 13. Roman to Integer ✅ | Golang | 4ms 2MB | Simple readable solution | 13-roman-to-integer-golang-4ms-2mb-simpl-96jj | \n\n# Code\n\nfunc romanToInt(s string) int {\nsum := 0\n\n\trim := map[string]int{\n\t\t"I": 1,\n\t\t"V": 5,\n\t\t"X": 10,\n\t\t"L": 50,\n\t\t"C": 100,\n\t\t"D | realtemirov | NORMAL | 2023-11-30T15:34:27.340543+00:00 | 2023-11-30T15:34:27.340566+00:00 | 2,483 | false | \n\n# Code\n```\nfunc romanToInt(s string) int {\nsum := 0\n\n\trim := map[string]int{\n\t\t"I": 1,\n\t\t"V": 5,\n\t\t"X": 10,\n\t\t"L": 50,\n\t\t"C": 100,\n\t\t"D": 500,\n\t\t"M": 1000,\n\t}\n\n\tfor i, ... | 31 | 0 | ['Go'] | 6 |
roman-to-integer | Golang simplest and efficient solution-- 100% faster | golang-simplest-and-efficient-solution-1-5nqd | \nfunc romanToInt(s string) int {\n var romanMap = map[byte]int{\'I\':1, \'V\':5, \'X\':10, \'L\':50, \'C\':100, \'D\':500, \'M\':1000}\n var result = rom | punitpandey | NORMAL | 2020-04-15T05:46:21.855996+00:00 | 2020-04-15T05:47:02.617369+00:00 | 3,505 | false | ```\nfunc romanToInt(s string) int {\n var romanMap = map[byte]int{\'I\':1, \'V\':5, \'X\':10, \'L\':50, \'C\':100, \'D\':500, \'M\':1000}\n var result = romanMap[s[len(s)-1]]\n \n for i := len(s)-2; i >= 0; i-- {\n if romanMap[s[i]] < romanMap[s[i+1]] {\n result -= romanMap[s[i]]\n ... | 31 | 0 | ['Go'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.