Java BigDecimal

  • + 12 comments

    My Java 8 lambda solution...

        //Write your code here
        Arrays.sort( s, (as,bs) -> {BigDecimal bd = new BigDecimal(bs); 
           return bd.compareTo(new BigDecimal(as));} );
    

    FAILED with...

    Exception in thread "main" java.lang.NullPointerException
      at java.math.BigDecimal.<init>(BigDecimal.java:806)
      at Solution.lambda`$main$`0(Solution.java:17)
    

    BECAUSE the provided code declared the array too large!

        // REPLACE:
        // String []s=new String[n+2];
    
        // WITH:
           String []s=new String[n];
    

    With the above fix, it now passes all TC's.