You are viewing a single comment's thread. Return to all comments →
my code is passed.I couldnot think of using ascii.My code is:
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*; import java.util.Arrays; public class Solution {
public static int numberNeeded(String first, String second) { int flength=first.length(); int slength=second.length(); //System.out.println("flength is"+flength); //System.out.println("slength is"+slength); char f[]=first.toCharArray(); char s[]=second.toCharArray(); int count=0; int fcount=0; int scount=0; int ans=0; if(flength>slength) { for(int i=0;i<flength;i++) { for(int j=0;j<slength;j++) { if(f[i]==s[j]) { s[j]=0; count++; break; } } } // System.out.println("if part"); ans=flength-count; } else if(flength<slength) { for(int i=0;i<flength;i++) { for(int j=0;j<slength;j++) { if(f[i]==s[j]) { s[j]=0; count++; break; } } } //System.out.println("elseif part"); ans=(flength+slength)-(2*count); } else { for(int i=0;i<flength;i++) { for(int j=0;j<slength;j++) { if(f[i]==s[j]) { count++; //f[i]=0; s[j]=0; break; } } } // System.out.println("else part"); ans=(flength-count)+(slength-count); } return ans; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String a = in.next(); String b = in.next(); System.out.println(numberNeeded(a, b)); }
} ....your solution is awesome.But what is the necessary of using ascii values.how can you think in this way?
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
my code is passed.I couldnot think of using ascii.My code is:
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*; import java.util.Arrays; public class Solution {
} ....your solution is awesome.But what is the necessary of using ascii values.how can you think in this way?