Posts

Showing posts from 2022

LeetCode Problem : Invert Binary Tree

Image
                 Problem Statement:-  Given the  root  of a binary tree, invert the tree, and return  its root .                 Solution

LeetCode : Symmetric Tree Problem

Image
              Problem statement:- Given the  root  of a binary tree,  check whether it is a mirror of itself  (i.e., symmetric around its center).                           Solution:-

Nth Prime Number Program

Image
 

Find First And Last Index Of Target Element In Sorted Array Using Java

Image
 

Print Numbers 1-10 Without Using Loop

Image
 

Reverse A String Keeping the Spaces Intact Using Java

Image
 

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 [ ] { } ; } }