Two Sum problem | Leetcode problem 1

preview_player
Показать описание
Two Sum problem.
Leetcode problem number 1.

JAVA interview programming playlist:

#java #interviewquestions #leetcode
Рекомендации по теме
Комментарии
Автор

Samajh kuch nhi aaya per dekh kr achha lga

satyam
Автор

brute force
to check is 2 numbers in an array adds to a particular sum

saikumarperamsetty
Автор

class Solution {
public int[] twoSum(int[] nums, int target) {
// int[] arr = {-1, -1};
// for(int i =0; i< nums.length; i++){
// for(int j =i+1; i< nums.length; i++){
// if(nums[i] + nums[j] == target){
// arr[0] = i;
// arr[1] = j;
// }
// }
// } O(n*n)
HashMap<Integer, Integer> map = new HashMap<>();
for(int i =0; i< nums.length; i++){
int req = target-nums[i];
if(map.containsKey(req)){
int[] arr = {map.get(req), i};
return arr;
}
map.put(nums[i], i);
}
return new int[]{-1, -1};
}
}

SingWithShivansh
Автор

good explaination, but you are missing time and space complexity in this explaination.

pnkkumar
Автор

Internal working nhi smj aayi hai..how it works behind the scene??

techrahul
Автор

How to do it withour hashmaps with Time complexity O(n)

manjotkaur
Автор

If the mode of number is zero it not palindrome this could be first check

raghuhg
Автор

u r explained in java what abiut python

venkateshvenkat
Автор

first show the program clearly end 2 end, if any one can take Screenshot of Every programs

saikumarperamsetty
welcome to shbcf.ru