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. Mybatis标签bind用法

    Mybatis使用bind元素进行模糊查询,不用在乎数据库是mysql还是oracle从而提高可移植性 使用bind元素传递多个参数 public List<Student> findSt ...

  2. HDU1160(KB12-J DP)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. nodejs 知识总结

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.添加模块:保存到package.json文件中; # npm install vue --save    注意 ...

  4. Wampserver配置与本地建站

    ☆根目录修改问题 /.修改运行根目录 1.修改apache配置,将服务请求定位到新目录下 →左击wampserver,点击Apache打开httpd.conf文件,Ctrl+f搜索documentro ...

  5. Android Studio支持Java1.8的解决方案

    Java1.8新添了一些特性,比如对lambda表达式的支持,父类推断等等,这篇文章讲述了1.8的新特性,有兴趣的同学可以点进去看看.但是由于AndroidStudio并不能直接支持Java1.8,我 ...

  6. Fiddler抓包使用教程-会话图标

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/72933882 本文出自[赵彦军的博客] 使用fiddler抓包时,会看到左侧按照顺 ...

  7. python SMTP 发送邮件

    #!/usr/bin/env/python # -*- coding: utf-8 -*- # @Time : 2018/11/19 9:56 # @Author : ChenAdong # @Ema ...

  8. 2.Hibernate的主配置文件hibernate.cfg.xml

    1.配置 Hibernate 需要事先知道在哪里找到映射信息,这些映射信息定义了 Java 类怎样关联到数据库表.Hibernate 也需要一套相关数据库和其它相关参数的配置设置.所有这些信息通常是作 ...

  9. 正则捕获url的?号传值

    http://www.baidu.com/Q?k=0012719021908563998510650 有时候,我们需要在静态页面捕获?号传值,这时就需要用到js的正则表达式. 例如:我们要获取上面这个 ...

  10. CSS| position定位和float浮动

    对基础知识再度做个巩固和梳理. 一.position定位 (一):position的属性 1.absolute:生成绝对定位的元素,相对于最近一级定位不是static的父元素来进行定位: 2.rela ...