zoukankan      html  css  js  c++  java
  • #Leetcode# 242. Valid Anagram

    https://leetcode.com/problems/valid-anagram/

    Given two strings s and , write a function to determine if t is an anagram of s.

    Example 1:

    Input: s = "anagram", t = "nagaram"
    Output: true
    

    Example 2:

    Input: s = "rat", t = "car"
    Output: false

    代码:

    class Solution {
    public:
        bool isAnagram(string s, string t) {
            map<char, int> mp;
            int ls = s.length(), lt = t.length();
            if(ls != lt) return false;
            for(int i = 0; i < ls; i ++)
                mp[s[i]] ++;
            for(int i = 0; i < lt; i ++)
                mp[t[i]] --;
            
            for(int i = 0; i < ls; i ++) {
                if(mp[s[i]]) return false;
                else continue;
            }
            return true;
        }
    };
    

      

  • 相关阅读:
    CF1515G
    杂题
    ARC120E
    CF1528F
    ICPC2021银川C
    gym102129F
    杂记6.15
    杂记5.12
    杂记4.1
    杂记3.17
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9963461.html
Copyright © 2011-2022 走看看