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. 纯HTML和CSS实现JD轮播图

    博主使用了纯HTML和CSS实现了JD的轮播图,没有加动态效果,主要是使用了定位的知识.  ,如图为两个侧边箭头图片(其实实际中应该使用CSS3的图标字体,这里没有使用). <!DOCTYPE ...

  2. Three.js开发指南---使用高级几何体和二元操作(第六章)

    本章的主要内容: 一,高级几何体-凸面体ConvexGeometry,扫描体LatheGeometry,管状几何体TubeGeometry: 二,使用拉伸几何体ExtrudeGeometry将一个二维 ...

  3. HDU4289(KB11-I 最小割)

    Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. 华中农业大学第五届程序设计大赛网络同步赛-L

    L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...

  5. DRF序列化/反序列化

    反序列化(不推荐版):两个字段 一个为正序准备,一个为反序准备重写create update方法 1. 确定数据结构: 自己定义key book_obj = { "title": ...

  6. js-redux学习笔记2

    1.为了 dispatch 一个 action,我们需要一个 dispatch 函数.可以用一个 action creator 去发送一个 action. var setNameActionCreat ...

  7. js-ES6学习笔记-正则的扩展

    1.在ES5中,RegExp构造函数的参数有两种情况.第一种情况是,参数是字符串,这时第二个参数表示正则表达式的修饰符(flag).第二种情况是,参数是一个正则表示式,这时会返回一个原有正则表达式的拷 ...

  8. Git 及 GitHub 使用

    Git bash 的常用命令 1. pwd    查看当前所在目录 2. cd cd ..         返回上一级 cd 目录    进入对应的目录 3. ls      查看当前文件夹的内容  ...

  9. jq塞入不同状态html的写法 switch (defaults.type)

    (function($) { //生成一个block function createBlock(options) { var defaults = { type: "1", } v ...

  10. SD从零开始33-37

    [原创]SD从零开始33 Billing简介 Billing在SD流程链中的集成: Billing document表征SD流程链中的最后功能: Billing document在R/3系统的不同区域 ...