Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6. public class Solution {
  7. public static int numberNeeded(String first, String second) {
  8. char arr1[]=first.toCharArray();
  9. char arr2[]=second.toCharArray();
  10. ArrayList<Character>ar=new ArrayList<Character>();
  11. ArrayList<Character>ar1=new ArrayList<Character>();
  12. for(int i=0;i<first.length();i++) //The code is running fine here
  13. {
  14. ar.add(arr1[i]);
  15. }
  16. for(int j=0;j<second.length();j++) //Although here when I am following the same algo it is giving an ArrayIndexOut Of Bounds Exception
  17. {
  18. ar1.add(arr2[j]);
  19. }
  20. for(int k=0;k<first.length();k++)
  21. {char c=ar.get(k);
  22. for(int l=0;l<second.length();l++)
  23. {
  24. char d=ar1.get(l);
  25. if(c==d)
  26. {
  27. ar.remove(k);
  28. ar1.remove(l);
  29. break;
  30. }
  31. }
  32. }
  33. int size=ar.size()+ar1.size();
  34. return size;
  35.  
  36. }
  37.  
  38. public static void main(String[] args) {
  39. Scanner in = new Scanner(System.in);
  40. String a = in.next();
  41. String b = in.next();
  42. System.out.println(numberNeeded(a, b));
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement