Solution by shifanaz


  • 0
    S

    '''public boolean compute(String ransomNote,String MagNote)
    {
    int count=0,mcount=0;
    for(int i=0;i<MagNote.length();i++)
    {
    Map<Character,Integer> map=new HashMap<Character,Integer>();
    char m1=MagNote.charAt(i);
    if(map.containsKey(m1))
    {
    map.get(m1);
    map.put(m1,++mcount);
    for(int j=0;j<ransomNote.length();j++)
    {
    char MN1=MagNote.charAt(i);
    char RN1=ransomNote.charAt(j);
    if(MN1==RN1)
    {
    map.put(m1, --mcount);
    if(mcount==0)
    return false;
    count++;
    System.out.println("Count Value: "+count);
    if(count==ransomNote.length())
    return true;
    }

    				   }
    			 }
    			 else
    				 map.put(m1,1);
    	    }
    	
    			return false;
    				
    }
    public static void main(String[] args) throws StringIndexOutOfBoundsException
    {
    	Scanner scan=new Scanner(System.in);
    	System.out.println("Enter the Ransom note: ");
    	String ranNote=scan.nextLine();
    	System.out.println("Enter the Magazine note: ");
    	String magNote=scan.nextLine();
    	MyRansNote obj1=new MyRansNote();
    	boolean ans=obj1.compute(ranNote, magNote);
    	System.out.println(ans);
    	
    }
    

    }
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.