Posts

Showing posts with the label ArrayDeque

Substring Of Size Three with Distinct Characters LeetCode

 Problem Link: https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/ Solution: class Solution {     public int countGoodSubstrings(String s) {             ArrayDeque<Character>aa=new ArrayDeque<Character>();             if(s.length()<3){                 return 0;             }         else{             int count=0;             aa.addLast(s.charAt(0));              aa.addLast(s.charAt(01));              aa.addLast(s.charAt(02));             if(s.charAt(0)!=s.charAt(1) && s.charAt(1)!=s.charAt(2) && s.charAt(0)!=s.charAt(2)){                 count++;       ...

Longest SubString Without Repeating Characters LeetCode

         Way 1 : Using ArrayDeque and ArrayList           int count=0;         int index=0;         ArrayList<Integer>aa=new ArrayList<Integer>();         ArrayDeque<Character> arr=new ArrayDeque<Character>();         for(int i=0;i<s.length();i++){             if(arr.contains(s.charAt(i))){                 aa.add(count); count=0;                 arr.clear(); i=index++;                              }             else{                 arr.addLast(s.charAt(i)); count++;             }         }       ...

ARRAYDEQUE IMPLEMENTATION IN JAVA WITH GENERICS WITHOUT USING INBUILT FUNCTIONS

USING DOUBLY LINKED LIST  class NodeImplementation<E>{ Node<E> head; Node<E> tail; static class Node<E>{ E data; Node<E> next; Node<E> prev; Node(E data){ this.data=data; this.next=null; this.prev=null; } } public void toAddHead(E data){ Node<E> newNode=new Node(data); if(head==null && tail==null){ System.out.println("Deque is empty"); head=newNode; tail=newNode; } else{ Node temp=head; newNode.prev=temp; temp.next=newNode; newNode.next=null; head=newNode; } } public void toAddTail(E data){ Node<E> newNode=new Node(data); if(head==null && tail==null){ System.out.println("List is Empty."); head=newNode; tail=newNode; } else{ Node temp=tail; newNode.next=temp; temp.prev=newNode; tail=newNode; newNode.prev=null; } } public void toRemoveTail(...