1. class Solution {
  2. public:
  3. bool isAnagram(string s, string t) {
  4. if(t=="") return s=="";
  5. map<char,int> m_s;
  6. map<char,int> m_t;
  7. int i=;
  8.  
  9. while(i<t.length()){
  10. if(m_t.find(t[i]) != m_t.end()) m_t[t[i]]++;
  11. else m_t.insert(pair<char,int>(t[i],));
  12. i++;
  13. }
  14.  
  15. i=;
  16. while(i<s.length()){
  17. if(m_s.find(s[i]) != m_s.end()) m_s[s[i]]++;
  18. else m_s.insert(pair<char,int>(s[i],));
  19. i++;
  20. }
  21.  
  22. map<char,int >::iterator it;
  23. for(it=m_s.begin();it!=m_s.end();it++){ //s belong t
  24. if(m_t[it->first] != it->second)
  25. {return false;}
  26. }
  27.  
  28. for(it=m_t.begin();it!=m_t.end();it++){ //t belong s
  29. if(m_s[it->first] != it->second)
  30. {return false;}
  31. }
  32.  
  33. return true;
  34.  
  35. }
  36. };

Valid Anagram的更多相关文章

  1. 【09_242】Valid Anagram

    Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...

  2. leetcode面试准备:Valid Anagram

    leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...

  3. 242. Valid Anagram(C++)

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

  4. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  5. 【LeetCode】242. Valid Anagram (2 solutions)

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

  6. [leetcode]242. Valid Anagram验证变位词

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

  7. leetcdoe Valid Anagram

    题目连接 https://leetcode.com/problems/valid-anagram/ Valid Anagram Description Given two strings s and ...

  8. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  9. LeetCode_242. Valid Anagram

    242. Valid Anagram Easy Given two strings s and t , write a function to determine if t is an anagram ...

  10. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

随机推荐

  1. iOS开发 - 网络数据安全加密(MD5)

    提交用户的隐私数据 一定要使用POST请求提交用户的隐私数据GET请求的所有参数都直接暴露在URL中请求的URL一般会记录在服务器的访问日志中服务器的访问日志是黑客攻击的重点对象之一 用户的隐私数据登 ...

  2. leetcode 116- Populating Next Right Pointers in Each Node

    题目: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode ...

  3. notpad++安装python插件

    1.安装python并添加到环境变量 2.在notpad++ 运行工具下点击运行,输入如下命令: cmd /k python "$(FULL_CURRENT_PATH)" & ...

  4. linux_x86_64 blat安装

    blatSrc35.zip下载地址:http://users.soe.ucsc.edu/~kent/src/ 对于下载好的源代码安装包blatSrc35.zip,需进行编译,安装过程如下: 1.用un ...

  5. Java 类型转换以及Object转成其他类型

    Object转int int count=(int)map.get("count") int count=Integer.parseInt((String)map.get(&quo ...

  6. The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation. 怎么解决

    cd 文件 pod install --no-repo-update 就可以了

  7. 解决Ueditor 不兼容IE7 和IE8

    引用Ueditor的js 的时候用 绝对路径

  8. PostgreSQL/bin

    pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...

  9. Leetcode: Mini Parser

    Given a nested list of integers represented as a string, implement a parser to deserialize it. Each ...

  10. java类的定义以及参数传递

    class类(类似结构体)的定义 import java.util.Scanner; import java.io.*; class student{//类的名称 public String name ...