brainfrz

Untitled

Oct 17th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.         public int compare(String s1, String s2) {
  2.             int n1 = s1.length();
  3.             int n2 = s2.length();
  4.             int min = Math.min(n1, n2);
  5.             for (int i = 0; i < min; i++) {
  6.                 char c1 = s1.charAt(i);
  7.                 char c2 = s2.charAt(i);
  8.                 if (c1 != c2) {
  9.                     c1 = Character.toUpperCase(c1);
  10.                     c2 = Character.toUpperCase(c2);
  11.                     if (c1 != c2) {
  12.                         c1 = Character.toLowerCase(c1);
  13.                         c2 = Character.toLowerCase(c2);
  14.                         if (c1 != c2) {
  15.                             // No overflow because of numeric promotion
  16.                             return c1 - c2;
  17.                         }
  18.                     }
  19.                 }
  20.             }
  21.             return n1 - n2;
  22.         }
Advertisement
Add Comment
Please, Sign In to add comment