代码随想录Day6

lc242

public class lc242 {
    public boolean isAnagram(String s, String t) {
        int [] record=new int[26];
        for (int i = 0; i < s.length(); i++) {
            record[s.charAt(i)-'a']++;
        }

        for (int i = 0; i < t.length(); i++) {
            record[t.charAt(i)-'a']--;
        }

        for (int i = 0; i < record.length; i++) {
            if (record[i]!=0){
                return  false;
            }
        }

        return true;
    }
}

lc349

public class lc349 {
    public int[] intersection(int[] nums1, int[] nums2) {

        HashSet<Integer> hs=new HashSet<>();
        for (int i : nums1) {
            for (int i1 : nums2) {
                if (i==i1){
                    hs.add(i);
                }
            }
        }

        int [] res=new int[hs.size()];
        int index=0;
        for (Integer h : hs) {
           res[index++]=h;
        }
        return  res;

    }
}

lc01

public class lc01 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hm=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            hm.put(nums[i],i);
        }

        for (int i = 0; i < nums.length; i++) {
            int j=target-nums[i];
            if (hm.containsKey(j)&&i!=hm.get(j)){
                return new int []{i,hm.get(j)};
            }
        }

        return null;
    }
}

全部评论

相关推荐

27双非本,最近面试被挂麻了面试官说简历内容太简单了,技术栈要单独一行,各位佬有啥建议吗
LZStarV:项目太简单了,你像用什么开发的技术栈没必要写一句话,按点写就好了;有特色的比如说WebSocket、视频流这种狠狠吹,那就好看多了
点赞 评论 收藏
分享
09-22 22:22
中山大学 Java
乌鱼子萨奇:羡慕你啊,直接转正了,都不用经历秋招的炼狱,但是你少经历了很多痛苦的事情啊
点赞 评论 收藏
分享
牛客96763241...:杭电✌️也是打完招呼,没人回吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务