0

I was trying out a question in which you have to determine that whether String s2 contains the permutations of String s1 or not?? I figured out the solution but... while doing the solution I was wondering how come my freq2.get(index) value which would return an object of Integer type is being stored in my "int" variable "temp" without giving any type of error or exception. Can someone please clear this doubt for me which is basically that how can we store an Integer object in int variable or vice-versa ?

public boolean checkInclusion(String s1, String s2) {
        int n = s1.length();
        int m = s2.length();
        
        if(m<n){
            return false;
        }
        
        ArrayList<Integer> freq1 = new ArrayList <Integer>();
        ArrayList<Integer> freq2 = new ArrayList<Integer>();
        
        for(int i= 0 ; i<30 ; i++){
            freq1.add(i,0); 
            freq2.add(i,0);
        }
        
        for(int i = 0 ; i<n ;i++){
            int index = s1.charAt(i)-'a';
            int temp = freq1.get(index);
            freq1.set(index , ++temp);
        }
        
        for(int i = 0 ; i<n ;i++){
            int index = s2.charAt(i)-'a';
            int temp = freq2.get(index);
            freq2.set(index , ++temp);
        }
         ........
        
        

0 Answers0