package Part1;

/**
 * Created by matao on 10/15/16.
 *
 * Given two strings, write a method to decide if one is a permutation of the other.
 * 给定两个字符串，确定其中一个字符串的字符重新排序后能否成为另一个字符串
 */
public class Q3 {
}

@@ -9,16 +9,91 @@
 Part1;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport java.util.Arrays;%0A%0A
 /**%0A * C
@@ -254,26 +254,1472 @@
 %E4%B8%B2%0A *
-/%0Apublic class Q3 %7B
+%0A * !!%E5%81%87%E5%AE%9A%E5%8F%98%E4%BD%8D%E8%AF%8D%E5%8C%BA%E5%88%86%E5%A4%A7%E5%B0%8F%E5%86%99%EF%BC%8C%E7%A9%BA%E7%99%BD%E4%B9%9F%E8%A6%81%E8%80%83%E8%99%91%0A */%0Apublic class Q3 %7B%0A%0A    public boolean permutation(String src, String dest) %7B%0A        if (src.length() != dest.length()) %7B%0A            return false;%0A        %7D%0A        return sort(src).equals(sort(dest));%0A    %7D%0A%0A    private String sort(String s) %7B%0A        char%5B%5D chars = s.toCharArray();%0A        Arrays.sort(chars);%0A        return String.valueOf(chars);%0A    %7D%0A%0A    /**%0A     * %E5%81%87%E8%AE%BE%E9%83%BD%E6%98%AFASCII%E5%AD%97%E7%AC%A6%EF%BC%8C%E5%88%99%E7%94%A8%E4%B8%80%E4%B8%AA128%E9%95%BF%E5%BA%A6%E7%9A%84int%E6%95%B0%E7%BB%84%EF%BC%8C%E4%BB%A3%E8%A1%A8%E6%AF%8F%E4%B8%AA%E5%AD%97%E7%AC%A6%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%0A     */%0A    public boolean permutation2(String src, String dest) %7B%0A        if (src.length() != dest.length()) %7B%0A            return false;%0A        %7D%0A        int%5B%5D letters = new int%5B128%5D;%0A        for (int i = 0; i %3C src.length(); i++) %7B%0A            char c = src.charAt(i);%0A            letters%5Bc%5D++;%0A        %7D%0A%0A        for (int i = 0; i %3C dest.length(); i++) %7B%0A            char c = dest.charAt(i);%0A            if (--letters%5Bc%5D %3C 0) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A%0A    @Test%0A    public void testPermutation() %7B%0A        Assert.assertEquals(true, permutation(%22apple%22, %22papel%22));%0A        Assert.assertEquals(true, permutation(%22carrot%22, %22tarroc%22));%0A        Assert.assertEquals(false, permutation(%22hello%22, %22llloh%22));%0A    %7D%0A%0A    @Test%0A    public void testPermutation2() %7B%0A        Assert.assertEquals(true, permutation2(%22apple%22, %22papel%22));%0A        Assert.assertEquals(true, permutation2(%22carrot%22, %22tarroc%22));%0A        Assert.assertEquals(false, permutation2(%22hello%22, %22llloh%22));%0A    %7D
 %0A%7D%0A

Revise solution of 1-3