Given two strings s and t , 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

Note:
You may assume the string contains only lowercase alphabets.

Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?

想法:将字符串s和字符串t分别转成容器存储,然后按字符顺序排序。再比较两个容器是否相等。

class Solution {
public:
    bool isAnagram(string s, string t) {
        vector<char> st1;
        vector<char> st2;
         ; i < s.size() ; i++){
            st1.push_back(s.at(i));
        }
        sort(st1.begin(),st1.end());
         ; j < t.size() ; j++){
            st2.push_back(t.at(j));
        }
                          sort(st2.begin(),st2.end());
                          return st1 == st2;
    }
};

leetcode242—Valid Anagram的更多相关文章

  1. leetcode242 Valid Anagram

    lc242 Valid Anagram 直接统计每种字母出现次数即可 class Solution { public boolean isAnagram(String s, String t) { i ...

  2. LeetCode242——Valid Anagram

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

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

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

  4. 【09_242】Valid Anagram

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

  5. leetcode面试准备:Valid Anagram

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

  6. 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. ...

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

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

  8. 【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 ...

  9. [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: ...

随机推荐

  1. C#生成二维码,裁切边框

    使用google zxing生成的二维码带有白色边框,显示在报告(使用Crystal Report 水晶报表)上时,由于空间有限造成二维码过小难以扫描识别. 通过将白色边框裁切掉,可以在有限的空间内最 ...

  2. Mybatis中的缓存

    Mybatis提供缓存查询功能,用于减轻数据库压力,提升数据查询能力. Mybatis中定义了两级缓存:包括一级缓存与二级缓存.示意图如下所示: 一.一级缓存 一级缓存的特点: 每一个SqlSessi ...

  3. MVC--DefaultModelBinder解析request参数

    转载:http://www.cnblogs.com/leotsai/p/ASPNET-MVC-DefaultModelBinder.html 看到很多ASP.NET MVC项目还在从request.q ...

  4. React之小知识点总结

    总结react中常常被忽略的小知识点 1)即使state里设置成和之前的值一样,render也会重新渲染 2)父组件传给子组件的属性(props是只读的,在子组件中已在this.state里将属性赋值 ...

  5. Java 社区平台 - Sym 1.7.0 发布

    English | 中文 简介 Symphony([ˈsɪmfəni],n.交响乐)是一个现代化的社区平台,因为它: 实现了面向内容讨论的论坛 包含了面向用户分享.交友.游戏的社交网络 集成了聚合独立 ...

  6. Linux CentOS 6.5 下 vsftpd ftp服务器搭建

    Linux CentOS 6.5 下 vsftpd ftp服务器搭建 by:授客 QQ:1033553122   操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.ce ...

  7. Intellij IDEA创建javaweb步骤详解

    一.创建并设置javaweb工程 1.创建javaweb工程File --> New --> Project... 设置工程名字: 创建完成后工程结构如下: 2. Web工程设置2.1 在 ...

  8. 安卓基础之Activity的四种启动模式

    Activity的四种启动模式   Activity的启动模式在清单文件中配置: <activity ... activity:lauchMode:"..."; //有四种模 ...

  9. Android--自定义弹出框-自定义dialog

    项目要用到弹出框,还要和苹果的样式一样(Android真是没地位),所以就自己定义了一个,不是很像(主要是没图),但是也还可以. 废话不多说了,直接上代码 1.先看布局文件 <?xml vers ...

  10. 与ServletContext相关的监听器

    概述 与ServletContext相关的监听器有ServletContextListener与ServletContextAttributeListener. ServletContextListe ...