Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
// Two Sum - Input Array is sorted - https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ class Solution { // Two pointers // Time Complexity: O(n) // Space Complexity: O(1) public int[] twoSum(int[] numbers, int target) { int i = 0, j = numbers.length - 1; while(i < j) { if(numbers[i] + numbers[j] == target) { return new int[]{i+1, j+1}; } else if (numbers[i] + numbers[j] > target) { j--; } else { i++; } } return new int[]{}; } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)