Flashcards
1. Two Sum
Cards in this deck (2)
- 11. Two Sumclass Solution {
public int[] twoSum(int[] nums, int target) {
int arr[]=new int[2];
HashMap map=new HashMap<>();
for(int i=0;i - 2167. Two Sum II - Input array is sortedclass Solution { //O(n)TC O (1)SC
public int[] twoSum(int[] nums, int target) {
int arr[]=new int[2];
int left=0;
int right=nums.length-1;
while(left<=right)
{
int element=nums[left]+nums[right];
if(element==target)
{
arr[0]=left+1;
arr[1]=right+1;
return arr;
}else if(element>target){
right--;
}else{
left++;
}
}
return arr;
}
}
Information
- Description
- Flashcards on 1. Two Sum, created by susheel rao on 13/05/2020.
- Created by
- susheel rao
- Views
- 2
- Rating