id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\nprivate:\n int f(string s, int ind, vector<int> &dp) {\n if(s[ind] == '0') return 0;\n if(ind == s.size()) return 1;\n if(ind == s.size() - 1) return 1;\n\n if(dp[ind] != -1) return dp[ind];\n\n string b = s.substr(ind, 2);\n\n int no_of_ways =...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\nprivate:\n int memoization(string s, int ind, vector<int> &dp) {\n if(s[ind] == '0') return 0;\n if(ind == s.size()) return 1;\n if(ind == s.size() - 1) return 1;\n\n if(dp[ind] != -1) return dp[ind];\n\n string b = s.substr(ind, 2);\n\n int no...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n=s.size();\n // return solve1(s, n, 0);\n\n vector<int> dp(n+1, -1);\n return solve2(s, n, 0, dp);\n }\nprivate:\n int solve2(string s, int n, int idx, vector<int> &dp){\n if(idx==n){\n re...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int dp[100];\n\n int decode(string s, int idx, int n) {\n cout << \"called : \" << idx << \" : \" << n << endl;\n if (idx == n) {\n cout << \"terminal : \" << idx << endl;\n return 1;\n }\n\n if (dp[idx] != -1) {\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int solve(string &s,int i,int cnt){\n if(i>=s.length())return cnt==s.length();\n if(dp[i][cnt]!=-1)return dp[i][cnt];\n int op1=0,op2=0;\n if(s[i]!='0')\n op1=solve(s,i+1,cnt+1);\n\n if(i<s.length()-1&&s[i]...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n vector<int>dp;\nbool check(int a){\n if(a>0&&a<=26)return true ;\n return false;\n}\nint f(string s,int idx){\n if(dp[idx]!=-1)return dp[idx];\n if(idx==s.size())return 1;\n int ans=0;\n string temp=\"\";\n temp+=s[idx];\n int a=stoi(temp);\n if(check(...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int rec(int level, string s, vector<int>& dp) {\n if (level == s.length()) return 1;\n if (s[level] == '0') return 0;\n if (dp[level] != -1) return dp[level];\n int cnt = 0;\n cnt += rec(level + 1, s, dp);\n if (level + 1 < s.length()...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n \n int solve(string &s, int i, string curr,unordered_map<string,int> &dp) {\n if(i == s.length()) {\n if(!curr.empty() && stoi(curr, 0, 10) > 0 && stoi(curr, 0, 10) <= 26) {\n return 1;\n }\n return 0;\n }\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n bool check(int i,int j,string &s){\n if(abs(j-i) >2 ) return false;\n if(s[i]=='0') return false;\n\n string a=\"\";\n for(int x=i;x<=j;x++) a+=s[x];\n\n if(stoi(a) >=1 && stoi(a)<=26) return true;\n\n return false;\n }\n\n int ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "\n// class Solution {\n// public:\n// int numDecodings(string s) {\n \n// int n = s.length();\n// if (n == 0 || s[0] == '0') return 0; // No valid decoding for empty or leading '0'\n\n// vector<int> dp(n+1,0);\n\n// dp[n] = 1; // Base case: an empty string has one ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "// Time Complexity: O(N), where N is length of the string. Memoization helps in pruning the recursion tree and hence decoding for an index only once. Thus this solution is linear time complexity.\n\n// Space Complexity: O(N). The dictionary used for memoization would take the space equal to the length of t...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int func(int i, string& s, map<string, int>& m,vector<int>&dp) {\n if (i == s.size()) return 1;\n if (i > s.size()) return 0;\n if(dp[i]!=-1) return dp[i];\n int take1 = 0, take2 = 0;\n if(s[i]!='0')\n take1 = func(i + 1, s, m,dp);\n\...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "// Time Complexity: O(N), where N is length of the string. Memoization helps in pruning the recursion tree and hence decoding for an index only once. Thus this solution is linear time complexity.\n\n// Space Complexity: O(N). The dictionary used for memoization would take the space equal to the length of t...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "// Time Complexity: O(N), where N is length of the string. Memoization helps in pruning the recursion tree and hence decoding for an index only once. Thus this solution is linear time complexity.\n\n// Space Complexity: O(N). The dictionary used for memoization would take the space equal to the length of t...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "// Time Complexity: O(N), where N is length of the string. Memoization helps in pruning the recursion tree and hence decoding for an index only once. Thus this solution is linear time complexity.\n\n// Space Complexity: O(N). The dictionary used for memoization would take the space equal to the length of t...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n int ways(int i, string &s, unordered_map<string, char>& mymap, vector<int>&dp){\n if(i>=s.size()) return 1;\n\n if(dp[i]!= -1) return dp[i];\n\n string one = s.substr(i, 1);\n string two = (i + 1 < s.size()) ? s.substr(i, 2) : \"\";\n\n in...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n unordered_map<string, int> dp;\n int decode(string s) {\n\n if(s.size() == 0) return 1;\n if(dp.find(s) != dp.end()) return dp[s];\n\n int ans = 0;\n\n int fc = stoi(s.substr(0, 1));\n if(fc != 0)\n {\n ans += decode(s.s...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n int dp[1001];\n\n bool isvalid(string c) {\n if(c.size() == 0 || c[0] == '0') {\n return false;\n }\n if(stoi(c) >= 1 && stoi(c) <= 26) {\n return true;\n }\n return false;\n }\n\n int findWays(string s, int ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n int dp[1001];\n\n bool isvalid(string c) {\n if(c.size() == 0 || c[0] == '0') {\n return false;\n }\n if(stoi(c) >= 1 && stoi(c) <= 26) {\n return true;\n }\n return false;\n }\n\n int findWays(string s, int ...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n class Solution {\npublic:\...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n class Solution {\npublic:\...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
92
<p>Given the <code>head</code> of a singly linked list and two integers <code>left</code> and <code>right</code> where <code>left &lt;= right</code>, reverse the nodes of the list from position <code>left</code> to position <code>right</code>, and return <em>the reversed list</em>.</p> <p>&nbsp;</p> <p><strong class="...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\nprivate:\n vector<string> result;\n void backtracking(string& s, int startIndex, int pointNum){\n if(pointNum == 3){\n if(isValid(s, startIndex, s.size() - 1)){\n result.push_back(s);\n }\n return;\n }\n for(int i ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\nprivate:\n vector<string> result;\n void backtracking(string &s,int startIndex, int pointNum){\n if(pointNum ==3){\n if(isValid(s,startIndex,s.size()-1)){\n result.push_back(s);\n }\n return;\n }\n for(int i=startI...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\n bool valid(const string& s, int start, int length) {\n return length == 1 ||\n (s[start] != '0' &&\n (length < 3 || s.substr(start, length) <= \"255\"));\n }\n\npublic:\n vector<string> restoreIpAddresses(string s) {\n vector<string> an...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n bool valid(const string& s, int left, int right) {\n if (left >= s.size()) {\n return false;\n }\n if (right < left) {\n return false;\n }\n if (right - left >= 3) {\n return false;\n }\n if (ri...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string> ans;\n vector<string> restoreIpAddresses(string s) {\n helper(s,0,0,s.size(),\"\");\n return ans;\n \n }\n\n void helper(string &s,int i,int dc,int n,string temp){\n if(dc==0 && (n-i>12 || n-i<4))\n return;\n i...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\nvoid fun(int i,int c,string& s,string& temp,vector<string>&ans)\n{\n if(c==4 && i==s.size())\n {\n temp.pop_back();\n ans.push_back(temp);\n temp.push_back('.');\n return;\n }\n if((c==4 && i<s.size()) || i==s.size())\n return;\n temp.push_back(s[i])...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n // https://leetcode.com/problems/restore-ip-addresses/\n auto isValidNum(const string_view s) {\n if (s.length() == 0 || s.length() > 3) return false;\n\t if (s.length() > 1 && s[0] == '0') return false;\n int val =0;\n for (int i=0; i < s.length();...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\n bool valid(const string& s, int start, int length) {\n return length == 1 ||\n (s[start] != '0' &&\n (length < 3 || s.substr(start, length) <= \"255\"));\n }\n\n void helper(const string& s, int startIndex, vector<int>& dots,\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n bool checkvalid(string str){\n int n=str.length();\n if(n==1) return true;\n if(n>3 ||str[0]=='0') return false;\n int value=stoi(str);\n if(value>255) return false;\n return true;\n }\n vector<string> restoreIpAddresses(string ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\n bool valid(const string& s, int start, int length) {\n return length == 1 ||\n (s[start] != '0' &&\n (length < 3 || s.substr(start, length) <= \"255\"));\n }\n\n void helper(const string& s, int startIndex, vector<int>& dots,\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n bool checkvalid(string str){\n int n=str.length();\n if(n==1) return true;\n if(n>3 ||str[0]=='0') return false;\n int value=stoi(str);\n if(value>255) return false;\n return true;\n }\n vector<string> restoreIpAddresses(string ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "\nclass Solution {\npublic:\n bool checkvalid(string str){\n int n=str.length();\n if(n==1) return true;\n if(n>3 ||str[0]=='0') return false;\n int value=stoi(str);\n if(value>255) return false;\n return true;\n }\n vector<string> restoreIpAddresses(strin...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\nprivate:\n bool check(string s) {\n int n = s.size();\n if (n > 3) {\n return false;\n }\n if (n > 1 && s[0] == '0') {\n return false;\n }\n int temp = stoi(s);\n if (temp > 255) {\n return false;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n int n = s.size();\n vector<string> ans;\n vector<string> t;\n function<void(int)> dfs = [&](int i) {\n if (i >= n && t.size() == 4) {\n ans.push_back(t[0] + \".\" + t[1] + \"...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n int n = s.size();\n vector<string> ans;\n vector<string> t;\n function<void(int)> dfs = [&](int i) {\n if (i >= n && t.size() == 4) {\n ans.push_back(t[0] + \".\" + t[1] + \"...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n int n = s.size();\n vector<string> ans;\n vector<string> t;\n function<void(int)> dfs = [&](int i) {\n if (i >= n && t.size() == 4) {\n ans.push_back(t[0] + \".\" + t[1] + \"...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n int n = s.size();\n vector<string> ans;\n vector<string> t;\n function<void(int)> dfs = [&](int i) {\n if (i >= n && t.size() == 4) {\n ans.push_back(t[0] + \".\" + t[1] + \"...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n bool valid(string& str,int start,int length){\n return (length==1 || (str[start]!='0' && (length<3 || str.substr(start,length)<=\"255\")));\n }\n void solve(int startIdx,string s,vector<int>&dots,vector<string>&ans){\n int remainingStr=s.length()-startIdx;...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "\nclass Solution {\n private:\n vector<string> res;\n vector<int> segs;\n void dfs(string& s, int part, int start) {\n if (part == 4) {\n // cout << part << segs[3] << endl;\n if (start == s.size()) {\n string temp;\n for (int i = 0; i <...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
0
{ "code": "class Solution {\npublic:\n vector<string>ans;\n void solve(string &s , int dotcnt , int prevdot , string str, int n ){\n if(dotcnt == 4 && prevdot == -1){\n reverse(str.begin() , str.end());\n ans.push_back(str);\n }\n\n if(dotcnt > 3 || prevdot < 0)return...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n vector<string> ans;\n int n = s.size();\n // iterate `s` - place 3 dots to have 4 segments \n // [seg1].[seg2].[seg3].[seg4]\n // 1st dot - we just need to run it 3 times at most\n // e....
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\npublic:\n vector<string> ans;\n string temp;\n bool inrange(string &s)\n {\n if(s.size()>3) return false;\n if(s.size()>1 && s[0]=='0') return false;\n if(s.size()<3) return true;\n if(s[0]>'2') return false;\n if(s[0]<'2') return true;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\npublic:\n bool valid(string temp){\n if(temp.size()>3 || temp.size()==0) return false;\n if(temp.size()>1 && temp[0]=='0') return false;\n if(temp.size() && stoi(temp)>255) return false; \n return true;\n }\n void solve(vector<string>& ans, string outp...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\n\npublic:\n\n vector<string> restoreIpAddresses(string s) {\n\n vector<string> ans;\n\n string k;\n\n for(int a=1;a<=3;a++){\n\n for(int b=1;b<=3;b++){\n\n for(int c=1;c<=3;c++){\n\n for(int d=1;d<=3;d++){\n\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\npublic:\n int n;\n vector<string> ans;\n void myf(int i, int cnt, string c, string s) {\n if(cnt > 4) return;\n if(i == n) {\n if(cnt != 4) return;\n auto d = c;\n d.pop_back();\n ans.push_back(d);\n return;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
1
{ "code": "class Solution {\n public:\n vector<string> restoreIpAddresses(const string& s) {\n vector<string> ans;\n dfs(s, 0, {}, ans);\n return ans;\n }\n\n private:\n void dfs(const string& s, int start, vector<string>&& path,\n vector<string>& ans) {\n if (path.size() == 4 && start == s.l...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\n public:\n vector<string> restoreIpAddresses(const string& s) {\n vector<string> ans;\n dfs(s, 0, {}, ans);\n return ans;\n }\n\n private:\n void dfs(const string& s, int st...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\nint n;\n\n vector<string>ans;\n bool isvalid(string str)\n {\n if(str[0]=='0')\n return false;\n int a = stoi(str);\n if(a>255)\n return false;\n\n return true;\n }\nvoid solve(string &s, int idx, int parts, string curr )\n{\n if(parts==4 && idx==n)\n {\n...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n bool isValid(string s){\n int n = s.size();\n\n if(n == 1){\n return true;\n }\n\n if(n > 3 || s[0] == '0'){\n return false;\n }\n\n int num = stoi(s);\n if(num > 255){\n return false;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n\n void helper(string str,int idx,vector<string>&temp,vector<string>&res){\n if(idx == str.length() && temp.size() == 4){\n\n string ans = temp[0] + \".\" + temp[1] + \".\" + temp[2] + \".\" + temp[3];\n\n res.push_back(ans);\n\n return;...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n vector<string> sol;\n bool isvalid(string str)\n {\n if(str.length() == 0)\n return false;\n if(stoi(str) > 255)\n return false;\n\n if(str.length() > 1 && str[0]=='0')\n return false;\n\n return true;\n }\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n\n bool is_valid(string s)\n {\n if(s[0]=='0')return false;\n\n int val=stoi(s);\n if(val>=256)return false;\n\n return true;\n }\n\n void solve(int i, string s, int par , string result ,vector<string>&ans)\n {\n // base case \n\n...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n vector<string> res;\n bool valid(string substring) {\n return substring != \"\" && !(substring[0] == '0' && substring.size() > 1);\n }\n\n vector<string> restoreIpAddresses(string s) {\n dfs(3,s,\"\");\n return res;\n }\n void dfs(int dotsL...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
2
{ "code": "class Solution {\npublic:\n int n;\n vector<string> ans;\n string sol;\n bool isValid(string s, int start, int end) {\n string temp = s.substr(start, end - start + 1);\n int ip = stoi(temp);\n \n if(s[start] == '0' && start != end) {\n //if ip is zero then...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\n bool isValid(string str) {\n if (str[0] == '0') {\n return false;\n }\n int number = stoi(str);\n if (number > 255) {\n return false;\n }\n return true;\n }\n\n void solve(int index, string s, int size, int parts, v...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n \n vector<string> ans;\n\n bool isValid(string s)\n {\n if(s[0]=='0')\n return false;\n int a= stoi(s);\n if(a<0 || a>255)\n return false;\n return true;\n }\n\n void solve(string s, int idx, int parts, string c...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\nint stringToInt(string s){\n int ans = 0;\n for(int i=(int)s.size()-1; i>=0; i--)\n ans += (s[i]-'0')*pow(10, s.size()-1-i);\n \n return ans;\n}\n\nbool checkString(string s){\n if(s.size() < 2)\n return true;\n if(s.size() >= 4)\n return fa...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool checkLeadingZeroes(string &IP) {\n return (IP.length() > 1 && IP[0] == '0');\n }\n\n void Restore(string &s, int i, int numPartitions, string &currIP, vector<string> &IP) {\n if (i == s.length()) {\n if (numPartitions != 4) return;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\nprivate:\n vector<string> answer;\n\n void helper(const string s, string curr, string sinceLastDot, const int indx, const int numDots) {\n if (numDots == 4 || (sinceLastDot != \"\" && stoi(sinceLastDot) > 255))\n return;\n\n if (indx == s.length()) {\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "#include <format>\n#include <numeric>\n#include <string>\n#include <vector>\n\nclass Solution {\n public:\n std::vector<std::string> restoreIpAddresses(std::string s) {\n const int n = s.size();\n std::vector<int> segments(4);\n std::vector<std::string> output;\n\n auto rec = [&](auto&& rec, i...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\nvector<string>res;//Handling of starting 0 is remaining\n\n\n string dotPutter(string temp, int i){\n int n=temp.length();\n string a=temp.substr(0,i+1)+'.'+temp.substr(i+1);\n return a;\n\n}\n\n\nbool checker(string temp,int dot){\n\n int n=temp.length(),i=0,x=0,j=0,...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> path;\n vector<vector<string>> res;\n int size = 0;\n vector<string> restoreIpAddresses(string s) {\n if (s.size() > 12) {\n return {};\n }\n backtrack(s, 0, 0);\n vector<string> ans;\n for (vector<string> ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\nprivate:\n vector<string> answer;\n\n void helper(const string s, string curr, string sinceLastDot, const int indx, const int numDots) {\n if (numDots == 4 || (sinceLastDot != \"\" && stoi(sinceLastDot) > 255))\n return;\n\n if (indx == s.length()) {\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string>ans;\n bool valid(string s){\n stringstream ss(s);\n string token;\n while(getline(ss,token,'.')){\n if((token.size()>3)||(token.size()>=2&&token[0]=='0')||(stoi(token)>255)){\n return false;\n }\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n vector<string> IpAddress;\n vector<string> restoreIpAddresses(string s) {\n if(s.length() > 12) return {};\n doRestoreIp(0, s, \"\");\n return ans;\n }\n void doRestoreIp(int index, string s, string curIpAddress){\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n vector<string> res;\n vector<int> splitArray;\n restoreIpAddressesUtil(s, 0, s.length(), splitArray, res);\n return res;\n }\n\n void restoreIpAddressesUtil(string s, int start, int n, vector<in...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isValid(string ip) {\n for(int i=0; i<ip.size(); i++) {\n if(ip[i] == '.') {\n ip[i] = ' ';\n }\n }\n stringstream ss(ip);\n vector<string> nums;\n string num;\n while(ss >> num) {\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool check(string str){\n if(str.length() > 3)return 0;\n if(str.length() > 1 && str[0]=='0')return 0;\n return stoi(str) < 256; \n \n return 1;\n }\n vector<vector<string>>ans;\n void helper(string s, int i, vector<string>v){\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n int n;\n vector<string> ans;\n void myf(int i, int cnt, string c, string s) {\n if(i == n) {\n if(cnt != 4) return;\n auto d = c;\n d.pop_back();\n ans.push_back(d);\n return;\n }\n if(s[i] == '...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool valid(string x){\n if(x[0]=='0')return false;\n int n=stoi(x);\n return n<=255;\n }\n void solve(string &s,vector<string>&ans,int idx,int part,string curr){\n if(part>5)return;\n if(idx==s.size()&&part==4){\n curr.pop_b...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n\n void checkValidIps(vector<string> s, vector<string> & ips){\n string ip = s[0] + \".\" + s[1] + \".\" + s[2] + \".\" + s[3];\n cout << ip << endl;\n\n if (s[0].size()>3 || s[1].size()>3 || s[2].size()>3 || s[3].size()>3) return;\n for (int i = 0;...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool valid(string& curr){\n string temp = \"\";\n for (int i=0 ; i<curr.size() ; i++){\n if ((curr[i] < 48 || curr[i] > 57 ) && (curr[i] != '.')) return 0;\n if (curr[i] == '.'){\n if (temp.size() > 3) return 0;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n struct DPValidAddress\n{\n set<string> firstSubset;\n set<string> secondSubset;\n set<string> thirdSubset;\n set<string> forthSubset;\n};\n\nvoid printSubnet(std::set<string> subnet)\n{\n for_each(subnet.begin(), subnet.end(), [](string str){\n std::cout << ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isValid(string ip) {\n for(int i=0; i<ip.size(); i++) {\n if(ip[i] == '.') {\n ip[i] = ' ';\n }\n }\n stringstream ss(ip);\n vector<string> nums;\n string num;\n while(ss >> num) {\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n return stoi(s) <= 255;\n }\n vector<string> addAll(string prefix, vector<string> v) {\n for (int i = 0; i<v.size(); i++) {\n if (v[i] == \"\") v[i] = prefix;\n else {\n v[i] = prefix + \".\" + v[...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n vector<string> res;\n vector<string> tempRes;\n helper(s, res, tempRes, 0);\n return res;\n }\n\n void helper(string& s, vector<string>& res, vector<string> tempRes, int index) {\n if (te...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n // unordered_set<string> ans;\n vector<string> ans;\n\n void solve(string s, vector<string> res){\n if (res.size() > 4) return;\n\n int n = s.size();\n if (n == 0){\n if (res.size() != 4) return;\n\n string cur_res;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isCorrect(string temp) {\n int i = 0;\n if(temp.back()=='.')\n return false;\n while (i < temp.length()) {\n if(temp[i]=='0'&& i<temp.length()-1 && temp[i+1]!='.'){\n return false;\n }\n if (t...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> ans;\n\n void solve(string s, vector<string> res){\n if (res.size() > 4) return;\n\n int n = s.size();\n if (n == 0){\n if (res.size() != 4) return;\n\n string cur_res;\n for (auto c: res){\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool valid(string s){\n if(s[0] == '0' && s.length() > 1){\n return false;\n }\n return stoi(s) <= 255;\n }\n \n void split(string s, int i, vector<vector<string>> &res, vector<string> curr){\n if(curr.size() > 4) return;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n string temp;\n bool check(string s) {\n if(s.size() == 0) return 0;\n int curr = 0;\n string t = \"\";\n if(s[0] == '.') return 0;\n for(int i = 0; i < s.size(); i++){\n if(s[i] == '.') {\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool checkLeadingZeroes(string &IP) {\n return (IP.length() > 1 && IP[0] == '0');\n }\n\n void Restore(string &s, int i, int numPartitions, string &currIP, vector<string> &IP) {\n if (i == s.length()) {\n if (numPartitions != 4) return;\n ...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string>ans;\n bool isvalid(int prev,int curr,string &s)\n {\n string substr=s.substr(prev,curr-prev+1);\n if((s[prev]=='0'&&prev!=curr)||curr-prev>=3)\n return false;\n int t=stoi(substr);\n if(t>=0&&t<=255)\n return t...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n void solve(int pos, int remainDots, string& s, vector<string>& ans, vector<string>& candidate, unordered_set<string>& st){\n\t\n if(pos==s.length()){\n if(remainDots==0){\n string k = \"\";\n for(int i=0;i<candidate.size();i++){...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n//有效IP不能有前导0,而且有数字范围,而且不能有特殊字符\n//忽略的一点:需要有四段\n//分割方式\n vector<string> res;\n\n bool isvaild(string t){\n if(t[0]=='0'&&t.size()>1) return false;\n for(char c:t){\n if(!isdigit(c)) return false;\n }\n int num=stoi(t);\n if(num>=...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n vector<string> possibleIps{};\n string ans{};\n recursiveSearch(s, possibleIps, ans, 0, 0);\n return possibleIps;\n }\nprivate:\n void recursiveSearch(const string& s, vector<string>& ret, strin...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isvalid(string s){\n if(s.size()==1)return true;\n else if(s.size() == 2){\n if(s[0]=='0')return false;\n return true;\n }\n else if(s.size() == 3){\n if(s[0] == '0')return false;\n int num=stoi(s);\...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n\n void solver(string & s, int it, int n, string cur, vector<string> & res, int cntr)\n {\n if(it == n && cntr == 4)\n {\n if(cur.back() == '.') cur.pop_back();\n\n res.push_back(cur);\n return;\n }\n\n string tmp...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "// 2024-09-13 22:44\n// sln1 23:12\nclass Solution {\npublic:\n vector<string> restoreIpAddresses(string s) {\n std::vector<string> out;\n dfs(s, 0, std::vector<std::string>(), out);\n return out;\n }\n\n void dfs(const std::string& s, int pos, std::vector<std::string> path,st...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n int n;\n vector<string> result;\n bool isValid(string str){\n if(str[0]=='0'){\n return false;\n }\n int value = stoi(str);\n return value<=255;\n }\n void solve(string& s,int index,int parts,string curr){\n if(index==...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n bool isvalid(string s){\n if(s.length() > 1 && s[0]=='0'){\n return false;\n }\n int val=stoi(s);\n return val>=0 && val<=255;\n } \n\n void f( vector<string>&res,string &s,string curr,int ind,int part){\n int n=s.length();\n if(ind==s.length() &&...
93
<p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> (<strong>inclusive</strong>) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</cod...
3
{ "code": "class Solution {\npublic:\n vector<string>result;\n bool isValid(string str){\n if(str[0] == '0'){\n return false;\n }\n int val = stoi(str);\n\n return val<=255;\n }\n void solve(string& s, int idx, int parts, string temp){\n int n = s.length();\n\n if(idx == n && part...