id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
6
<p>The string <code>&quot;PAYPALISHIRING&quot;</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p> <pre> P A H N A P L S I I G Y I R </pre> <p>And then read line by line: <code>&quot;PAHNAPLSIIGYIR&quot;<...
3
{ "code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if(numRows==1 || numRows==s.size())\n return s;\n string result[numRows][s.size()];\n int row=0,col=0,curr=0;\n while(curr<s.size()){\n while(row<numRows && curr<s.size()){\n ...
6
<p>The string <code>&quot;PAYPALISHIRING&quot;</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p> <pre> P A H N A P L S I I G Y I R </pre> <p>And then read line by line: <code>&quot;PAHNAPLSIIGYIR&quot;<...
3
{ "code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n if (numRows == 1 || numRows >= s.size()) {\n return s;\n }\n \n vector<vector<char>> pattern(numRows, vector<char>(s.size(), '\\0'));\n int temp = 0;\n int j = 0;\n\n for (in...
6
<p>The string <code>&quot;PAYPALISHIRING&quot;</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p> <pre> P A H N A P L S I I G Y I R </pre> <p>And then read line by line: <code>&quot;PAHNAPLSIIGYIR&quot;<...
3
{ "code": "class Solution {\npublic:\n string convert(string s, int numRows) {\n // Edge case: if numRows is 1, no zigzagging is required\n if (numRows == 1) return s;\n\n // Initialize a 2D vector with numRows and enough columns for the string\n vector<vector<char>> vec(numRows, vector...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n long long int reverse(long long x) {\n long long int ans=0;\n while(x!=0){\n long long int digit=x%10;if((ans>INT_MAX/10)||(ans<INT_MIN/10)){\n return 0;\n }\n ans=(ans*10)+digit;\n x=x/10;\n }\n...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int ans=0,rem;\n while(x!=0){\n rem=x%10;\n x/=10;\n if(ans>INT_MAX/10 || ans<INT_MIN/10)\n return 0;\n ans=ans*10+rem;\n\n }\n return ans;\n \n \n }\n};",...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n long long ans = 0;\n\n while(x != 0){\n int digit = x%10;\n ans = ans*10 + digit;\n x/=10;\n }\n\n if(ans >= INT_MAX || ans <= INT_MIN) return 0;\n return ans;\n }\n};", "memory": ...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int temp = x;\n int ans=0;\n while(temp != 0){\n int last = temp % 10;\n if((ans > INT_MAX /10) || (ans< INT_MIN/10)){\n return 0;\n }\n ans = ans*10 + last;\n te...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int temp = x;\n int ans=0;\n while(temp != 0){\n int last = temp % 10;\n if((ans > INT32_MAX /10) || (ans< INT32_MIN/10)){\n return 0;\n }\n ans = ans*10 + last;\n ...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n long n=0;\n while(x!=0){\n n=n*10+x%10;\n x=x/10;\n if(n>INT_MAX || n<INT_MIN){\n return 0;\n }\n }\n return n;\n }\n};", "memory": "8200" }
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int reversed = 0;\n while (x) {\n int temp = x % 10;\n if ((reversed > INT_MAX / 10) || (reversed < INT_MIN / 10)) {\n return 0;\n }\n x = x / 10;\n reversed = reversed ...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n\n long long int rev =0;\n int rem=0;\n \n \n if (x>0){\n while (x>0){\n rem=x%10;\n //if (rev > (LLONG_MAX - rem) / 10 || rev < (LLONG_MIN - rem) / 10) {\n // return 0;...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
0
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int reversed = 0;\n while (x != 0) {\n int pop = x % 10;\n x /= 10;\n if (reversed > INT_MAX / 10 || (reversed == INT_MAX / 10 && pop > 7)) return 0;\n if (reversed < INT_MIN / 10 || (reversed ==...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
2
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n // Return immediately if x is zero\n if(x == 0) return x;\n\n int rev = 0; // This will store the reversed number\n int temp; // Temporary variable to hold the last digit\n bool negative = false; // Flag to check...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
2
{ "code": "class Solution {\npublic:\n \n \n int reverse(int x) {\n int revNum=0;\n while(x!=0){\n int ld=x%10;\n if (revNum > INT_MAX / 10 ) return 0;\n if (revNum < INT_MIN / 10 ) return 0;\n revNum=revNum*10+ld;\n x/=10;\n }\n ...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n long long revNum = 0;\n while(x != 0){\n int digit = x % 10;\n revNum = revNum * 10 + digit;\n x /= 10;\n }\n if(revNum < INT_MIN || revNum > INT_MAX) return 0;\n return revNum;\n }\...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n long t=0;\n while(x){\n t=t*10+x%10;\n x/=10;\n if(t<INT_MIN || t>INT_MAX) return 0;\n }\n \n return int(t);\n }\n};", "memory": "8500" }
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n bool sign = false;\n if(x<0) sign=true;\n x = abs(x);\n vector<int> digits;\n while(x>0){\n digits.push_back(x%10);\n x/=10;\n }\n long ans=0;\n for(int i=0;i<digits.size();i+...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int comp(string a, string b){\n int n = a.size();\n int m = b.size();\n int flag = 0;\n if(n<m) return 1;\n else{\n m = m-1;\n for(int i = 0; i<n; i++){\n\n if(a[i]>b[(m)] && !flag){ return 0;}\n ...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n vector<int> digits;\n while(x!=0)\n {\n int dig = x%10;\n x=x/10;\n digits.push_back(dig);\n }\n for(int i=digits.size()-1;i>=0;i--)\n {\n if( x +digits[i]*pow(10,digi...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int count = 0;\n int n = abs(x);\n vector<int> v;\n while(n>0){\n count++;\n v.push_back(n%10);\n n = n/10;\n }\n count = count-1;\n\n int ans = 0;\n for(int i=0;i<...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n /*int i = 0;\n int result = 0;\n while(x != 0) {\n std::cout << \"x : \" << x << std::endl;\n std::cout << \"i : \" << i << std::endl;\n std::cout << result << std::endl;\n std::cout << \"...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\npublic:\n int reverse(int x) {\n int count = 0;\n int n = abs(x);\n vector<int> v;\n while(n>0){\n count++;\n v.push_back(n%10);\n n = n/10;\n }\n count = count-1;\n\n int ans = 0;\n for(int i=0;i<...
7
<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p> <p><strong>Assume the environment does...
3
{ "code": "class Solution {\nprivate:\n bool overflowNum(const int& digit, const int& n) {\n if (digit > 2 && n > 8) return true;\n return false;\n }\n\n bool overflowNum(const int& max_num, const int& a, const int& b) {\n if (a > max_num - b) return true;\n return false;\n }\npublic:\...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "#include <string>\n#include <limits> // for std::numeric_limits\n\nclass Solution {\npublic:\n int myAtoi(const std::string& s) {\n int i = 0;\n int n = s.size();\n int sign = 1;\n long long result = 0;\n\n // Skip leading whitespace\n while (i < n && s[i] == ' ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n //O(n) time complexity\n //O(1) space complexity.\n int myAtoi(const string& s) {\n int ptr = 0;\n\n //Ignore leading whitespace\n while (ptr < s.size() && s[ptr] == ' ') {\n ptr++;\n }\n\n if (ptr == s.size()) return 0; //a...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n \nint myAtoi(const string& str) {\n int i = 0;\n int n = str.length();\n // Skip leading spaces\n while (i < n && str[i] == ' ') {\n i++;\n }\n\n // Check if the string is empty after removing spaces\n if (i == n) return 0;\n\n // Check for optio...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string str) {\n int res = 0, sign = 1, i = 0;\n // handle empty string\n if (str.empty()) return 0;\n // handle leading spaces\n while (str[i] == ' ') ++i;\n // handle sign\n if (str[i] == '+' || str[i] == '-') {\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int n=s.size();\n int i=0,si=1;\n while(i<n && s[i]==' ') i++;\n\n long long res=0;\n if(i<n && (s[i]=='+'||s[i]=='-')){\n si=(s[i]=='+')?1:-1;\n i++;\n }\n\n \n while(i<n &...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int i=0;\n int sign=1;\n long ans=0;\n while(i<s.length() && s[i]==' ')\n i++;\n if(s[i]=='-')\n {\n sign=-1;\n i++;\n }\n else if(s[i]=='+')\n i++;\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int ans = 0;\n int i=0,f=1;\n while(i<s.length() && s[i]==' ') {\n i++;\n }\n if(s[i]=='+'){\n f=1;\n i++;\n } else if(s[i]=='-') {\n f=-1;\n i++;\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n long num=0;\n int i=0;\n int sign=1;\n\n while(s[i]==' ') i++;\n if(s[i]=='-' || s[i]=='+'){\n sign=(s[i]=='-')?-1:1;\n i++;\n }\n while(i<s.length() && isdigit(s[i])){\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "#include <iostream>\n#include <climits> // For INT_MAX and INT_MIN\nusing namespace std;\n\nclass Solution {\npublic:\n int myAtoi(string s) {\n int index = 0;\n int n = s.length();\n int sign = 1;\n long long result = 0; // Use long long to handle overflow\n\n // St...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
0
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int front = 1;\n int num = 0;\n int flag = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == ' ') {\n if (flag == 1) {\n break;\n }\n contin...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
1
{ "code": "class Solution {\npublic:\n int myAtoi(string s) \n {\n int i=0;\n int sign=1;\n long ans=0;\n while(i<s.length() && s[i]==' ')\n i++;\n if(s[i]=='-')\n {\n sign=-1;\n i++;\n }\n else if(s[i]=='+')\n i...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
1
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n\n int ans = 0;\n int signState = 0;\n bool fresh = true;\n\n for(int i = 0; i<s.length() ;i++){\n if(fresh){\n if( !signState && !ans) {\n if(s[i]=='+')\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
2
{ "code": "class Solution {\n public:\n int myAtoi(string s) {\n trim(s);\n if (s.empty())\n return 0;\n\n const int sign = s[0] == '-' ? -1 : 1;\n if (s[0] == '+' || s[0] == '-')\n s = s.substr(1);\n\n long num = 0;\n\n for (const char c : s) {\n if (!isdigit(c))\n break;\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
2
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n long ans = 0;\n int sign = 1;\n int i = 0;\n\n while (s[i] == ' ') i++;\n\n if (s[i] == '-' || s[i] == '+') {\n sign = (s[i] == '-') ? -1 : 1;\n i++;\n }\n while (i < s.length() && is...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int len = s.size();\n double num = 0;\n int i=0;\n while(s[i] == ' '){\n i++;\n }\n bool positive = s[i] == '+';\n bool negative = s[i] == '-';\n positive == true ? i++ : i;\n n...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\n public:\n int myAtoi(string s) {\n trim(s);\n if (s.empty())\n return 0;\n\n const int sign = s[0] == '-' ? -1 : 1;\n if (s[0] == '+' || s[0] == '-')\n s = s.substr(1);\n\n long num = 0;\n\n for (const char c : s) {\n if (!isdigit(c))\n break;\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n void trim(string& s){\n s.erase(0,s.find_first_not_of(' '));\n s.erase(s.find_last_not_of(' ') + 1);\n }\n int myAtoi(string s) {\n trim(s);\n int sign = s[0] == '-'? -1:1;\n if(s[0]=='+' || s[0]=='-')\n s = s.substr(1);\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n \n int i = 0, n = s.length();\n bool neg = false;\n \n if (n == 0)\n return 0;\n \n while (i < n && s[i] == ' ')\n i++;\n \n if (i < n && s[i] == '-')\n {\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n bool flag = true,b=false;\n string f = \"\";\n int count = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == '-' && !count && !b) {\n b=true;\n flag = false;\n } e...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n bool neg = false;\n int i = 0;\n int n = s.length();\n if (n == 0) {\n return 0;\n }\n while (i < n && s[i] == ' ') {\n i++;\n }\n if (i < n && s[i] == '-') {\n i...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n bool neg = false;\n int i = 0;\n int n = s.length();\n if (n == 0) {\n return 0;\n }\n while (i < n && s[i] == ' ') {\n i++;\n }\n if (i < n && s[i] == '-') {\n i...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n bool neg = false;\n int i = 0;\n int n = s.length();\n if (n == 0) {\n return 0;\n }\n while (i < n && s[i] == ' ') {\n i++;\n }\n if (i < n && s[i] == '-') {\n i...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n int reading = 0;\n int negative = 0;\n int overone = 0;\n string temp;\n for(int i = 0; i < s.length(); i++){\n if(s[i] == ' ' && !reading) continue;\n if(s[i] == '+' && !reading){\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n string starttrim(const string &s) {\n size_t start = find_if_not(s.begin(), s.end(), [](unsigned char ch) { return isspace(ch); }) - s.begin();\n return s.substr(start);\n }\n\n string endtrim(const string &s) {\n size_t end = find_if_not(s.rbegin()...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n bool flag = true, state = true;\n int tmp = 0;\n string str = \"\";\n int res = 0;\n\n for (int i=0; i<s.size(); ++i) {\n if (state && s[i]==' ')\n continue;\n else if (state && s...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n try\n {\n return std::stoi(s);\n }\n catch(const std::invalid_argument& e)\n {\n return 0;\n }\n catch(...)\n {\n if (s.find(\"-\") != std::string::npos)\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n //whitespace\n int sol = 0;\n bool minus = false;\n while(s.size() && s[0] ==' ')\n s=s.substr(1);\n cout<<s;\n if(s[0] == '-')\n {\n minus = true;\n s=s.substr(1);\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n\n if (s.empty())\n return 0;\n\n // Ignore any leading whitespace\n std::size_t found = s.find_first_not_of(\" \"); // Find the position of 1st non-whitespace character\n if (found != std::string::npos)\n ...
8
<p>Implement the <code>myAtoi(string s)</code> function, which converts a string to a 32-bit signed integer.</p> <p>The algorithm for <code>myAtoi(string s)</code> is as follows:</p> <ol> <li><strong>Whitespace</strong>: Ignore any leading whitespace (<code>&quot; &quot;</code>).</li> <li><strong>Signedness</strong...
3
{ "code": "class Solution {\npublic:\n int myAtoi(string s) {\n // Remove whitespace\n while (s != \"\" and s[0] == ' ') {\n s = s.substr(1);\n }\n\n if (s == \"\") {\n return 0;\n }\n\n // Remove sign\n auto sign = 1;\n if (s[0] == '-')...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s);) {\n if(s[0]=='-'){\n out<<\"false\\n\";\n continue;\n }\n int i =0;\n int j = s.length()-1;\n bool an...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s);) {\n if(s[0]=='-'){\n out<<\"false\\n\";\n continue;\n }\n int i =0;\n int j = s.length()-1;\n bool an...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s);) {\n if(s[0]=='-'){\n out<<\"false\\n\";\n continue;\n }\n int i =0;\n int j = s.length()-1;\n bool an...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "int init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n ofstream out(\"user.out\");\n for (string s; getline(cin, s);) {\n if(s[0]=='-'){\n out<<\"false\\n\";\n continue;\n }\n int i =0;\n int j = s.length()-1;\n bool an...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0) return false;\n int temp=x;\n long sum=0;\n\n while(temp!=0){\n sum=sum*10+(temp%10);\n temp/=10;\n }\n\n return x==sum;\n }\n};", "memory": "8100" }
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0){\n return false;\n }\n int original = x;\n double reversed = 0;\n double a ;\n while(original>0){\n \n a = original % 10;\n reversed = reversed * 10 + a;\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0){\n return false;\n }\n long long t=x;\n long long y = 0;\n long long z = t;\n while(z){\n y = y*10 + z%10;\n z = z/10;\n }\n \n if(t==y)\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n int reverseNumber(int x)\n {\n long long reverse = 0;\n int digit;\n while(x>0)\n {\n digit = x%10;\n x/=10;\n reverse = reverse*10 + digit;\n } \n return reverse;\n }\n \n bool isPalindrom...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n int reverse(int x){\n long r = 0;\n while(x){\n r = r*10 + x%10;\n x = x/10;\n }\n if(r<INT_MIN || r>INT_MAX)\n return 0;\n \n return int(r);\n }\n\n bool isPalindrome(int x) {\n if(x<0)\n...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n // If x is negative, it can't be a palindrome\n if (x < 0) {\n return false;\n }\n \n int dp = x; // Store the original number\n int rv = 0; // To store the reversed number\n \n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0) return false;\n long long num = x;\n long long ans = 0;\n while(x){\n int digit = x%10;\n ans = ans*10 + digit;\n x /= 10; \n }\n return ans == num;\n }\n};\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0) return false;\n long long aux = x;\n long long inv = 0;\n while(aux!=0)\n {\n int c = aux % 10;\n inv = inv*10 + c;\n aux = aux / 10;\n }\n if(inv == x) retu...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0) return false;\n long long num = x;\n long long ans = 0;\n while(x){\n int digit = x%10;\n ans = ans*10 + digit;\n x /= 10; \n }\n return ans == num;\n }\n};", ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
0
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n long y=0;\n if(x<0){\n return false;\n }\n long c=x;\n while(c!=0){\n y=y*10;\n y=(c%10)+y;\n c=c/10;\n }\n if(y==x){\n return true;\n }...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x == 0)\n return true;\n int y = x;\n long long n = 0;\n while (x > 0)\n {\n n = n * 10 + x % 10;\n x /= 10;\n }\n if (n == y)\n return true;\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n long long reversed = 0;\n if(x == 0){\n return true;\n }\n if(x<0){\n return false;\n }\n long long temp = x;\n while(temp != 0){\n reversed = (reversed * 10) + (tem...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n int cnt = 0;\n int y = x;\n if (x < 0)\n return false;\n while (y) {\n y = y / 10;\n cnt++;\n }\n int cnt1 = cnt;\n int z = x / (pow(10, (cnt - 1)));\n for (i...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n int b=x;\n int n=0;\n if (b<0)\n return false;\n if (b==0)\n return true;\n while (b>0){\n b=b/10;\n n++;\n }\n b=x;\n int rer = 0;\n while ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n int b=x;\n int n=0;\n if (b<0)\n return false;\n if (b==0)\n return true;\n while (b>0){\n b=b/10;\n n++;\n }\n b=x;\n while (b>0){\n in...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution\n{\npublic:\n bool isPalindrome(int x)\n {\n if (x < 0)\n return false;\n bool flag = true;\n int size = 0;\n int num = x;\n while (num > 0)\n {\n size++;\n num = num / 10;\n }\n int* arr;\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0) return 0;\n string s = \"\";\n int prod=1;\n while(x){\n s.push_back(char(x%10+48));\n x = (x-(x%10))/10;\n }\n for(int i =0,j=s.size()-1; i<=j; i++,j--){\n prod *=...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x<0) return false;\n int n =0;\n int y = 0;\n string s= \"\";\n if(x==0) return true;\n while(x>0){\n s+= x%10+48;\n x/=10;\n n++;\n }\n if(n%2){\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string reverse=\"\";\n bool palindrome=true;\n int dummy=x;\n while(x!=0){\n int last_digit=x%10;\n reverse+=(char)(last_digit+'0');\n x=x/10;\n }\n if(dummy>0){\n for(int i=0;i<reverse.size()/2;i++){\...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n\tif (x < 0) \n\t\treturn false;\n\t\n\tint head = x;\n\tint head2 = x;\n\tint tail = 0;\n\tint count = 0;\n\twhile (head > 0) {\n\t\thead /= 10;\n\t\tcount++;\n\t}\n\tint *arr = new int[count];\n\tfor (int i = 0; i < count; i++) {\n\t\ttail = head...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0) {\n return false; // Negative numbers are not palindromes\n }\n\n int arr[50];\n int counter = 0;\n int original = x; // Save the original value of x for later use\n\n // Extract digi...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n //check for negative int\n if(x<0){\n return false;\n }\n int digits[100];\n int index=0;\n while(x>0){\n digits[index]=x%10;\n x=x/10;\n index++;\n }\n int left=0;...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x<0){return false;}\n int a[31];\n int count = 0;\n while(x>9){\n a[count] = x % 10;\n count++;\n x=x/10;\n }\n a[count] = x;\n int i =0;\n bool detected =...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n int arr[100];\n int rem=x;\n int count=0;\n if(x<0){\n return false;\n }\n while(rem>0){\n arr[count]=rem%10;\n rem=rem/10;\n count++;\n }\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n\tbool isPalindrome(int x) {\n\n\t\tif ((x < 0) || (x == 10)||x == 100 || x == 1000 || x == 10000 || x == 100000 || x == 1000000) {\n\t\t\treturn false;\n\t\t}\n\t\tif ((x < 10) && (x > 0)) {\n\t\t\treturn true;\n\t\t}\n \n\n\t\tint b = x;\n\t\tint k = 1;\n\t\twhile (b > 9) {\...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0)\n return false;\n if (x > -1 && x < 10)\n return true;\n \n vector<int> digits;\n digits.reserve(16);\n\n while(x > 0){\n digits.push_back(x % 10);\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n\tbool isPalindrome(int x) {\n\n\t\tif ((x < 0) || (x == 10) || x == 100 || x == 1000 || x == 10000 || x == 100000 || x == 1000000) {\n\t\t\treturn false;\n\t\t}\n\t\tif ((x < 10) && (x > 0)) {\n\t\t\treturn true;\n\t\t}\n\n\n\t\tint b = x;\n\t\tint k = 1;\n\t\twhile (b > 9) {\n\...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x < 0)\n return false;\n \n string str = to_string(x);\n size_t i{}, len = str.length();\n --len;\n while(i < len) {\n if(str[i] != str[len]) {\n return false;\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0) return false; // minus\n if (x == 0) return true; // 0\n\n // 1. store digits of integer to array;\n //std::vector<int> digits;\n\n // To string\n std::string str = std::to_string(x);\n /...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string str=to_string(x);\n int s=0;\n int e=str.size()-1;\n\n while(s<e){\n if(str[s]!=str[e]){\n return false;\n }\n else {\n s++;\n e--;\n }\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string s=to_string(x);\n for(int i=0;i<=(s.size()-1)/2;i++){\n if(s[i]!=s[s.size()-1-i]){\n return false;\n }\n }\n return true;\n }\n};", "memory": "10300" }
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n\n if(x<0) return false;\n\n std::string s = std::to_string(x);\n int size = s.size();\n int end = size-1;\n int start1 = 0;\n \n while(start1<end){\n if(isalnum(s[start1]) !=0 && isalnum...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0) return false; // minus\n if (x == 0) return true; // 0\n\n // 1. store digits of integer to array;\n //std::vector<int> digits;\n\n // To string\n std::string str = std::to_string(x);\n s...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string number = to_string(x);\n for(int i=0 ; i<number.size() ; i++){\n if(number[i] != number[number.size()-i-1]){\n //std::cout<<number[i]<<\" \"<<number[number.size()-i];\n return(false);\n...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string s=std::to_string(x);\n int left=0;\n int right=s.length()-1;\n while(left<right){\n if(s[left]!=s[right]){\n return false;\n }\n left+=1;\n right-=1;\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string s = to_string(x);\n int l = 0;\n int r = s.length()-1;\n while(l<r){\n if(s[l] != s[r]){\n return false;\n } \n l++;\n r--;\n }\n return...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x < 0) return false;\n if(x < 10) return true;\n string s = to_string(x);\n int len = s.length();\n for(int i = 0; i < len/2; i++){\n if(s[i] != s[len - i - 1]) return false;\n }\n ret...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "/*\nOriginal solution. JV.\n*/\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n ios::sync_with_stdio(false); \n cin.tie(NULL);\n cout.tie(NULL);\n \n string y = to_string(x);\n\n for(int i = 0, j = y.size() - 1; i < j; i++, j--){\n if(y[i] ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n string num = to_string(x);\n int arrlen = num.length();\n if (arrlen % 2 == 0 && x % 11 != 0) {\n return false;\n }\n for(int i = 0; i < arrlen /2 ; i++) {\n char temp = num[i];\n ...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if (x < 0){\n return false;\n }\n\n string num = to_string(x);\n int len = num.length();\n int half = len / 2;\n if (len % 2 == 0){ // even\n reverse(num.begin(), num.begin() + half)...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x < 0)\n return 0;\n \n string nums = \"\";\n while(x)\n {\n nums.push_back(char(x%10));\n x /= 10;\n }\n string temp = nums;\n reverse(nums.begin(), nums....
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "#include <string>\n\nclass Solution {\npublic:\n bool isPalindrome(int x) {\n std::string num = std::to_string(x);\n int length = num.length();\n std::string num1 = num.substr(0, length/2);\n std::string num2;\n if(length % 2 == 0)\n num2 = num.substr(length...
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n if(x < 0)\n return 0;\n \n string nums = \"\";\n while(x)\n {\n nums.push_back(char(x%10));\n x /= 10;\n }\n string temp = nums;\n reverse(nums.begin(), nums....
9
<p>Given an integer <code>x</code>, return <code>true</code><em> if </em><code>x</code><em> is a </em><span data-keyword="palindrome-integer"><em><strong>palindrome</strong></em></span><em>, and </em><code>false</code><em> otherwise</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <str...
3
{ "code": "class Solution {\npublic:\n bool isPalindrome(int x) {\n long long reversed = 0;\n long long temp = abs(x);\n while(temp!=0)\n {\n reversed+= (temp%10)*pow(10,std::to_string(temp).length()-1);\n temp/=10;\n }\n if(reversed == x) return true;\n ...