Posts

Showing posts from January, 2022

Leetcode :(Remove Duplicates From the Sorted Array)

Image
 

Count Words In A List Of String Using Java 8

Image

Leetcode:(ValidPalindrome) Problem

Image
 

Leetcode:(Valid Paranthesis) Problem

Image
 

Leetcode:(Length of Longest Substring) Problem

Image
 

LeetCode :-(Two Sum) Problem

Image
import java . util . HashMap ; import java . util . Map ; class TwoSum { // Time complexity: O(n) private static int [ ] findTwoSum ( int [ ] nums , int target ) { Map < Integer , Integer > numMap = new HashMap < > ( ) ; for ( int i = 0 ; i < nums . length ; i ++ ) { int complement = target - nums [ i ] ; if ( numMap . containsKey ( complement ) ) { return new int [ ] { numMap . get ( complement ) , i } ; } else { numMap . put ( nums [ i ] , i ) ; } } return new int [ ] { } ; } }