题解 | #确定两串乱序同构#

确定两串乱序同构

https://www.nowcoder.com/practice/164929d4acd04de5b0ee2d93047b3b20

import java.util.*;

public class Same {
    public boolean checkSam(String stringA, String stringB) {
        // write code here
        if (stringA.length() != stringB.length()) {
            return false;
        }
        int [] map1 = new int[256];
        int [] map2 = new int[256];
        for (int i = 0; i < stringA.length(); i++) {
            map1[stringA.charAt(i)]++;
            map2[stringB.charAt(i)]++;
        }
        for (int i = 0; i < 256; i++) {
            if(map1[i]!=map2[i])
                return false;
        }
        return true;

    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务