Reverse int within the 32-bit signed integer rangeReverse int within the 32-bit signed integer range: $[−2^31, 2^31 − 1]$ OptimizedCombining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”Reverse int within the 32-bit signed integer range: $[−2^31, 2^31 − 1]$ Optimized

Why not increase contact surface when reentering the atmosphere?

How does the UK government determine the size of a mandate?

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Purchasing a ticket for someone else in another country?

How to Reset Passwords on Multiple Websites Easily?

How does it work when somebody invests in my business?

Do the temporary hit points from the Battlerager barbarian's Reckless Abandon stack if I make multiple attacks on my turn?

How did Doctor Strange see the winning outcome in Avengers: Infinity War?

Was Spock the First Vulcan in Starfleet?

Pole-zeros of a real-valued causal FIR system

Would a virus be able to change eye and hair colour?

Term for the "extreme-extension" version of a straw man fallacy?

Is there a korbon needed for conversion?

How to be diplomatic in refusing to write code that breaches the privacy of our users

Opposite of a diet

What can we do to stop prior company from asking us questions?

Is oxalic acid dihydrate considered a primary acid standard in analytical chemistry?

Two monoidal structures and copowering

Proof of work - lottery approach

Why Were Madagascar and New Zealand Discovered So Late?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How do I extract a value from a time formatted value in excel?

Increase performance creating Mandelbrot set in python

Where does the Z80 processor start executing from?



Reverse int within the 32-bit signed integer range


Reverse int within the 32-bit signed integer range: $[−2^31, 2^31 − 1]$ OptimizedCombining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”Reverse int within the 32-bit signed integer range: $[−2^31, 2^31 − 1]$ Optimized













4












$begingroup$


Problem




Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Optimized code here.




Feedback



I'm looking for any ways I can optimize this with modern C++ features overall. I hope my use of const-correctness, exception handling, and assertions is implemented well here, please let me know. Is there any way I can use byte operations to reverse the int and keep track of the sign possibly?



Based on the submission feedback from LeetCode, is it safe to say that the time complexity is $O(n)$ and space complexity is $O(n)$? If I can reduce the complexity in anyway would love to know!



enter image description here



#include <cassert>
#include <climits>
#include <stdexcept>
#include <string>

class Solution

public:
int reverse(int i)
bool is_signed = false;
if(i < 0) is_signed = true;

auto i_string = std::to_string(i);

std::string reversed = "";
while(!i_string.empty())
reversed.push_back(i_string.back());
i_string.pop_back();


try
i = std::stoi(reversed);
catch (const std::out_of_range& e)
return 0;


if(is_signed) i *= -1;

return i;

;

int main()

Solution s;
assert(s.reverse(1) == 1);
assert(s.reverse(0) == 0);
assert(s.reverse(123) == 321);
assert(s.reverse(120) == 21);
assert(s.reverse(-123) == -321);
assert(s.reverse(1207) == 7021);
assert(s.reverse(INT_MAX) == 0);
assert(s.reverse(INT_MIN) == 0);










share|improve this question











$endgroup$











  • $begingroup$
    This leetcode.com/problems/reverse-integer ?
    $endgroup$
    – Martin R
    Mar 23 at 18:39










  • $begingroup$
    Yes that's the one
    $endgroup$
    – greg
    Mar 23 at 19:03










  • $begingroup$
    The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
    $endgroup$
    – CiaPan
    yesterday















4












$begingroup$


Problem




Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Optimized code here.




Feedback



I'm looking for any ways I can optimize this with modern C++ features overall. I hope my use of const-correctness, exception handling, and assertions is implemented well here, please let me know. Is there any way I can use byte operations to reverse the int and keep track of the sign possibly?



Based on the submission feedback from LeetCode, is it safe to say that the time complexity is $O(n)$ and space complexity is $O(n)$? If I can reduce the complexity in anyway would love to know!



enter image description here



#include <cassert>
#include <climits>
#include <stdexcept>
#include <string>

class Solution

public:
int reverse(int i)
bool is_signed = false;
if(i < 0) is_signed = true;

auto i_string = std::to_string(i);

std::string reversed = "";
while(!i_string.empty())
reversed.push_back(i_string.back());
i_string.pop_back();


try
i = std::stoi(reversed);
catch (const std::out_of_range& e)
return 0;


if(is_signed) i *= -1;

return i;

;

int main()

Solution s;
assert(s.reverse(1) == 1);
assert(s.reverse(0) == 0);
assert(s.reverse(123) == 321);
assert(s.reverse(120) == 21);
assert(s.reverse(-123) == -321);
assert(s.reverse(1207) == 7021);
assert(s.reverse(INT_MAX) == 0);
assert(s.reverse(INT_MIN) == 0);










share|improve this question











$endgroup$











  • $begingroup$
    This leetcode.com/problems/reverse-integer ?
    $endgroup$
    – Martin R
    Mar 23 at 18:39










  • $begingroup$
    Yes that's the one
    $endgroup$
    – greg
    Mar 23 at 19:03










  • $begingroup$
    The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
    $endgroup$
    – CiaPan
    yesterday













4












4








4





$begingroup$


Problem




Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Optimized code here.




Feedback



I'm looking for any ways I can optimize this with modern C++ features overall. I hope my use of const-correctness, exception handling, and assertions is implemented well here, please let me know. Is there any way I can use byte operations to reverse the int and keep track of the sign possibly?



Based on the submission feedback from LeetCode, is it safe to say that the time complexity is $O(n)$ and space complexity is $O(n)$? If I can reduce the complexity in anyway would love to know!



enter image description here



#include <cassert>
#include <climits>
#include <stdexcept>
#include <string>

class Solution

public:
int reverse(int i)
bool is_signed = false;
if(i < 0) is_signed = true;

auto i_string = std::to_string(i);

std::string reversed = "";
while(!i_string.empty())
reversed.push_back(i_string.back());
i_string.pop_back();


try
i = std::stoi(reversed);
catch (const std::out_of_range& e)
return 0;


if(is_signed) i *= -1;

return i;

;

int main()

Solution s;
assert(s.reverse(1) == 1);
assert(s.reverse(0) == 0);
assert(s.reverse(123) == 321);
assert(s.reverse(120) == 21);
assert(s.reverse(-123) == -321);
assert(s.reverse(1207) == 7021);
assert(s.reverse(INT_MAX) == 0);
assert(s.reverse(INT_MIN) == 0);










share|improve this question











$endgroup$




Problem




Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Optimized code here.




Feedback



I'm looking for any ways I can optimize this with modern C++ features overall. I hope my use of const-correctness, exception handling, and assertions is implemented well here, please let me know. Is there any way I can use byte operations to reverse the int and keep track of the sign possibly?



Based on the submission feedback from LeetCode, is it safe to say that the time complexity is $O(n)$ and space complexity is $O(n)$? If I can reduce the complexity in anyway would love to know!



enter image description here



#include <cassert>
#include <climits>
#include <stdexcept>
#include <string>

class Solution

public:
int reverse(int i)
bool is_signed = false;
if(i < 0) is_signed = true;

auto i_string = std::to_string(i);

std::string reversed = "";
while(!i_string.empty())
reversed.push_back(i_string.back());
i_string.pop_back();


try
i = std::stoi(reversed);
catch (const std::out_of_range& e)
return 0;


if(is_signed) i *= -1;

return i;

;

int main()

Solution s;
assert(s.reverse(1) == 1);
assert(s.reverse(0) == 0);
assert(s.reverse(123) == 321);
assert(s.reverse(120) == 21);
assert(s.reverse(-123) == -321);
assert(s.reverse(1207) == 7021);
assert(s.reverse(INT_MAX) == 0);
assert(s.reverse(INT_MIN) == 0);







c++ c++11 interview-questions integer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 mins ago









Jamal

30.4k11121227




30.4k11121227










asked Mar 23 at 18:31









greggreg

39928




39928











  • $begingroup$
    This leetcode.com/problems/reverse-integer ?
    $endgroup$
    – Martin R
    Mar 23 at 18:39










  • $begingroup$
    Yes that's the one
    $endgroup$
    – greg
    Mar 23 at 19:03










  • $begingroup$
    The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
    $endgroup$
    – CiaPan
    yesterday
















  • $begingroup$
    This leetcode.com/problems/reverse-integer ?
    $endgroup$
    – Martin R
    Mar 23 at 18:39










  • $begingroup$
    Yes that's the one
    $endgroup$
    – greg
    Mar 23 at 19:03










  • $begingroup$
    The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
    $endgroup$
    – CiaPan
    yesterday















$begingroup$
This leetcode.com/problems/reverse-integer ?
$endgroup$
– Martin R
Mar 23 at 18:39




$begingroup$
This leetcode.com/problems/reverse-integer ?
$endgroup$
– Martin R
Mar 23 at 18:39












$begingroup$
Yes that's the one
$endgroup$
– greg
Mar 23 at 19:03




$begingroup$
Yes that's the one
$endgroup$
– greg
Mar 23 at 19:03












$begingroup$
The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
$endgroup$
– CiaPan
yesterday




$begingroup$
The problem is ill-posed. If 'the' reverse of 120 is 21, how can you know whether 'the' reverse of 21 should be 120 or 12? What makes 'the' reverse of 1 number 1 and not 10000? How can you tell your code solves the problem if the correct solution is not defined?
$endgroup$
– CiaPan
yesterday










1 Answer
1






active

oldest

votes


















8












$begingroup$

General comments



  • There is no reason to use a class. Instead, the functionality should be made into a free function.


  • Your code is overly complicated. There is no reason to make new string from which you erase characters one-by-one. Instead, you can convert the input integer to a string and use a standard function to reverse that.


  • Also, pay attention to const correctness. This protects from unintended mistakes and helps the compiler optimize more.


I would simplify your function to just:



int reverse(int i) 

try

auto reversed std::to_string(i) ;
std::reverse(reversed.begin(), reversed.end());

const auto result std::stoi(reversed) ;
return i < 0 ? -1 * result : result;

catch (const std::out_of_range& e)

return 0;




Further comments




  • If you want to have a fast solution, you should avoid std::string altogether. This you can do by "iterating" through the digits using arithmetic operations (division and modulus), as in (using std::string to only show you what is happening):



    int x = 1234;
    std::string s;

    while (x > 0)

    s.push_back('0' + (x % 10));
    x /= 10;


    std::cout << s << "n"; // Prints 4321


    I will let you take it from here to use these ideas to make your program even faster.



  • Regarding your theoretical question concerning complexity, if we assume that the input is treated as a string of n characters, there is $Omega(n)$ lower bound by a trivial adversary argument. Basically, if you don't spend at least n time, you can't read the whole of the input, and then you cannot guarantee correct output on every instance.






share|improve this answer











$endgroup$












  • $begingroup$
    Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
    $endgroup$
    – greg
    Mar 25 at 1:59










  • $begingroup$
    if you'd like to see the optimized version I've edited my post
    $endgroup$
    – greg
    2 days ago






  • 1




    $begingroup$
    @greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
    $endgroup$
    – Juho
    2 days ago






  • 1




    $begingroup$
    @esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
    $endgroup$
    – Juho
    2 days ago










  • $begingroup$
    Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
    $endgroup$
    – greg
    yesterday











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216068%2freverse-int-within-the-32-bit-signed-integer-range%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8












$begingroup$

General comments



  • There is no reason to use a class. Instead, the functionality should be made into a free function.


  • Your code is overly complicated. There is no reason to make new string from which you erase characters one-by-one. Instead, you can convert the input integer to a string and use a standard function to reverse that.


  • Also, pay attention to const correctness. This protects from unintended mistakes and helps the compiler optimize more.


I would simplify your function to just:



int reverse(int i) 

try

auto reversed std::to_string(i) ;
std::reverse(reversed.begin(), reversed.end());

const auto result std::stoi(reversed) ;
return i < 0 ? -1 * result : result;

catch (const std::out_of_range& e)

return 0;




Further comments




  • If you want to have a fast solution, you should avoid std::string altogether. This you can do by "iterating" through the digits using arithmetic operations (division and modulus), as in (using std::string to only show you what is happening):



    int x = 1234;
    std::string s;

    while (x > 0)

    s.push_back('0' + (x % 10));
    x /= 10;


    std::cout << s << "n"; // Prints 4321


    I will let you take it from here to use these ideas to make your program even faster.



  • Regarding your theoretical question concerning complexity, if we assume that the input is treated as a string of n characters, there is $Omega(n)$ lower bound by a trivial adversary argument. Basically, if you don't spend at least n time, you can't read the whole of the input, and then you cannot guarantee correct output on every instance.






share|improve this answer











$endgroup$












  • $begingroup$
    Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
    $endgroup$
    – greg
    Mar 25 at 1:59










  • $begingroup$
    if you'd like to see the optimized version I've edited my post
    $endgroup$
    – greg
    2 days ago






  • 1




    $begingroup$
    @greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
    $endgroup$
    – Juho
    2 days ago






  • 1




    $begingroup$
    @esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
    $endgroup$
    – Juho
    2 days ago










  • $begingroup$
    Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
    $endgroup$
    – greg
    yesterday
















8












$begingroup$

General comments



  • There is no reason to use a class. Instead, the functionality should be made into a free function.


  • Your code is overly complicated. There is no reason to make new string from which you erase characters one-by-one. Instead, you can convert the input integer to a string and use a standard function to reverse that.


  • Also, pay attention to const correctness. This protects from unintended mistakes and helps the compiler optimize more.


I would simplify your function to just:



int reverse(int i) 

try

auto reversed std::to_string(i) ;
std::reverse(reversed.begin(), reversed.end());

const auto result std::stoi(reversed) ;
return i < 0 ? -1 * result : result;

catch (const std::out_of_range& e)

return 0;




Further comments




  • If you want to have a fast solution, you should avoid std::string altogether. This you can do by "iterating" through the digits using arithmetic operations (division and modulus), as in (using std::string to only show you what is happening):



    int x = 1234;
    std::string s;

    while (x > 0)

    s.push_back('0' + (x % 10));
    x /= 10;


    std::cout << s << "n"; // Prints 4321


    I will let you take it from here to use these ideas to make your program even faster.



  • Regarding your theoretical question concerning complexity, if we assume that the input is treated as a string of n characters, there is $Omega(n)$ lower bound by a trivial adversary argument. Basically, if you don't spend at least n time, you can't read the whole of the input, and then you cannot guarantee correct output on every instance.






share|improve this answer











$endgroup$












  • $begingroup$
    Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
    $endgroup$
    – greg
    Mar 25 at 1:59










  • $begingroup$
    if you'd like to see the optimized version I've edited my post
    $endgroup$
    – greg
    2 days ago






  • 1




    $begingroup$
    @greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
    $endgroup$
    – Juho
    2 days ago






  • 1




    $begingroup$
    @esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
    $endgroup$
    – Juho
    2 days ago










  • $begingroup$
    Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
    $endgroup$
    – greg
    yesterday














8












8








8





$begingroup$

General comments



  • There is no reason to use a class. Instead, the functionality should be made into a free function.


  • Your code is overly complicated. There is no reason to make new string from which you erase characters one-by-one. Instead, you can convert the input integer to a string and use a standard function to reverse that.


  • Also, pay attention to const correctness. This protects from unintended mistakes and helps the compiler optimize more.


I would simplify your function to just:



int reverse(int i) 

try

auto reversed std::to_string(i) ;
std::reverse(reversed.begin(), reversed.end());

const auto result std::stoi(reversed) ;
return i < 0 ? -1 * result : result;

catch (const std::out_of_range& e)

return 0;




Further comments




  • If you want to have a fast solution, you should avoid std::string altogether. This you can do by "iterating" through the digits using arithmetic operations (division and modulus), as in (using std::string to only show you what is happening):



    int x = 1234;
    std::string s;

    while (x > 0)

    s.push_back('0' + (x % 10));
    x /= 10;


    std::cout << s << "n"; // Prints 4321


    I will let you take it from here to use these ideas to make your program even faster.



  • Regarding your theoretical question concerning complexity, if we assume that the input is treated as a string of n characters, there is $Omega(n)$ lower bound by a trivial adversary argument. Basically, if you don't spend at least n time, you can't read the whole of the input, and then you cannot guarantee correct output on every instance.






share|improve this answer











$endgroup$



General comments



  • There is no reason to use a class. Instead, the functionality should be made into a free function.


  • Your code is overly complicated. There is no reason to make new string from which you erase characters one-by-one. Instead, you can convert the input integer to a string and use a standard function to reverse that.


  • Also, pay attention to const correctness. This protects from unintended mistakes and helps the compiler optimize more.


I would simplify your function to just:



int reverse(int i) 

try

auto reversed std::to_string(i) ;
std::reverse(reversed.begin(), reversed.end());

const auto result std::stoi(reversed) ;
return i < 0 ? -1 * result : result;

catch (const std::out_of_range& e)

return 0;




Further comments




  • If you want to have a fast solution, you should avoid std::string altogether. This you can do by "iterating" through the digits using arithmetic operations (division and modulus), as in (using std::string to only show you what is happening):



    int x = 1234;
    std::string s;

    while (x > 0)

    s.push_back('0' + (x % 10));
    x /= 10;


    std::cout << s << "n"; // Prints 4321


    I will let you take it from here to use these ideas to make your program even faster.



  • Regarding your theoretical question concerning complexity, if we assume that the input is treated as a string of n characters, there is $Omega(n)$ lower bound by a trivial adversary argument. Basically, if you don't spend at least n time, you can't read the whole of the input, and then you cannot guarantee correct output on every instance.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago









esote

2,89611038




2,89611038










answered Mar 23 at 18:50









JuhoJuho

1,536612




1,536612











  • $begingroup$
    Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
    $endgroup$
    – greg
    Mar 25 at 1:59










  • $begingroup$
    if you'd like to see the optimized version I've edited my post
    $endgroup$
    – greg
    2 days ago






  • 1




    $begingroup$
    @greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
    $endgroup$
    – Juho
    2 days ago






  • 1




    $begingroup$
    @esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
    $endgroup$
    – Juho
    2 days ago










  • $begingroup$
    Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
    $endgroup$
    – greg
    yesterday

















  • $begingroup$
    Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
    $endgroup$
    – greg
    Mar 25 at 1:59










  • $begingroup$
    if you'd like to see the optimized version I've edited my post
    $endgroup$
    – greg
    2 days ago






  • 1




    $begingroup$
    @greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
    $endgroup$
    – Juho
    2 days ago






  • 1




    $begingroup$
    @esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
    $endgroup$
    – Juho
    2 days ago










  • $begingroup$
    Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
    $endgroup$
    – greg
    yesterday
















$begingroup$
Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
$endgroup$
– greg
Mar 25 at 1:59




$begingroup$
Trying the digit iteration now, great concept that I'm adding to my toolbox. Fantastic feedback.
$endgroup$
– greg
Mar 25 at 1:59












$begingroup$
if you'd like to see the optimized version I've edited my post
$endgroup$
– greg
2 days ago




$begingroup$
if you'd like to see the optimized version I've edited my post
$endgroup$
– greg
2 days ago




1




1




$begingroup$
@greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
$endgroup$
– Juho
2 days ago




$begingroup$
@greg I'd be happy to comment on that as well, but you shouldn't change your code after you've received an answer. Instead, you should post it as a separate question.
$endgroup$
– Juho
2 days ago




1




1




$begingroup$
@esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
$endgroup$
– Juho
2 days ago




$begingroup$
@esote Great, thanks for the edits! I know how to use Latex now on this site too :-)
$endgroup$
– Juho
2 days ago












$begingroup$
Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
$endgroup$
– greg
yesterday





$begingroup$
Updated the code here codereview.stackexchange.com/questions/216300/… learning math operations to pop and push digits has been very valuable in optimizing this
$endgroup$
– greg
yesterday


















draft saved

draft discarded
















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216068%2freverse-int-within-the-32-bit-signed-integer-range%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar