前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LeetCode 0242 - Valid Anagram

LeetCode 0242 - Valid Anagram

作者头像
Reck Zhang
发布2021-08-11 12:07:36
1510
发布2021-08-11 12:07:36
举报
文章被收录于专栏:Reck Zhang

Valid Anagram

Desicription

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

Example 1:

代码语言:javascript
复制
Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

代码语言:javascript
复制
Input: s = "rat", t = "car"
Output: false

Note:

You may assume the string contains only lowercase alphabets.

Solution

代码语言:javascript
复制
class Solution {
public:
    bool isAnagram(string s, string t) {
        vector<int> s_cnt(26, 0);
        vector<int> t_cnt(26, 0);
        for(const auto& a : s) {
            s_cnt[a - 'a']++;
        }
        for(const auto& a : t) {
            t_cnt[a - 'a']++;
        }
        return s_cnt == t_cnt;
    }
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-12-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Valid Anagram
    • Desicription
      • Solution
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档