My Ruby Solution


  • 0
    T

    Time Complexity - O(logn)
    Space Complexity - O(1)

    def two_sum(numbers, target)
        be = 0
        en = numbers.length - 1
        
        while be < en
            cur = numbers[be] + numbers[en]
            if cur == target
                return [be + 1, en + 1]
            elsif cur < target
                be += 1
            else
                en -= 1
            end
        end
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.