I felt like doing an algorithm and found this problem on leetcode
Given an array of integers, find two numbers such that they add up to a specific target num
Just curious, but what's wrong with this O(n) solution?
public int[] twoSum(int[] nums, int target) { for (int i = 0; i < nums.length - 1; i++){ if (nums[i] + nums[i+1] == target) return new int[] {i, i+1}; } return null; }