DEV Community

Cover image for LeetCode's Add Two Integers Solution - Java
Piyush Acharya
Piyush Acharya

Posted on • Edited on

3

LeetCode's Add Two Integers Solution - Java

2235. Add Two Integers

Intuition

I first looked at the inputs that are given to the program. I walked through a simple version of the problem in my head and then in pseudocode.

Approach

I take the 2 inputs, add them together, and return the sum.

Complexity

  • Time complexity:
    O(1)

  • Space complexity:
    O(1)

Code

GitHub: https://github.com/Verisimilitude11/LeetCode-Problems/tree/main/2235.%20Add%20Two%20Integers

class Solution {
    public int sum(int num1, int num2) {
        return num1 + num2;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Great read:

Is it Time to go Back to the Monolith?

History repeats itself. Everything old is new again and I’ve been around long enough to see ideas discarded, rediscovered and return triumphantly to overtake the fad. In recent years SQL has made a tremendous comeback from the dead. We love relational databases all over again. I think the Monolith will have its space odyssey moment again. Microservices and serverless are trends pushed by the cloud vendors, designed to sell us more cloud computing resources.

Microservices make very little sense financially for most use cases. Yes, they can ramp down. But when they scale up, they pay the costs in dividends. The increased observability costs alone line the pockets of the “big cloud” vendors.