godkingjay / LeetCode

LeetCode Solutions
MIT License
32 stars 67 forks source link

[PROBLEM] 7. Reverse Integer #98

Closed godkingjay closed 11 months ago

godkingjay commented 11 months ago

Difficulty

Medium

Problem Description

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

Example 1:

Input: x = 123
Output: 321

Example 2:

Input: x = -123
Output: -321

Example 3:

Input: x = 120
Output: 21

Constraints:

  • -231 <= x <= 231 - 1

Link

https://leetcode.com/problems/reverse-integer/

VSen910 commented 11 months ago

Hey I've got a Java solution, would you please assign this to me?

VSen910 commented 11 months ago

I just noticed a C++ and Java solution for the same already exists in the repo whose space complexity is O(n), but I have a got a different approach to it whose time complexity is O(n) and space is O(1), so shall I go ahead with that?

godkingjay commented 11 months ago

I just noticed a C++ and Java solution for the same already exists in the repo whose space complexity is O(n), but I have a got a different approach to it whose time complexity is O(n) and space is O(1), so shall I go ahead with that?

You can try doing it like this:

// Solution https://github.com/godkingjay/LeetCode/issues/1
class Solution {
  /*
   * Code for Solution https://github.com/godkingjay/LeetCode/issues/1
   */
}

// Solution https://github.com/godkingjay/LeetCode/issues/2
class Solution {
  /*
   * Code for Solution https://github.com/godkingjay/LeetCode/issues/2
   */
}

or like this:

LeetCode/
├── [DIFFICULTY]/
│   ├── [PROBLEM]/
│   │   ├── README
│   │   ├── solution.java
│   │   ├── solution.cpp
│   │   ├── [MY APPROACH]/
│   │   │   ├── README
│   │   │   ├── solution.java
│   │   │   └── ...
│   │   └── ...