首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >LeetCode 242. Valid Anagram

LeetCode 242. Valid Anagram

作者头像
ShenduCC
发布于 2020-04-08 03:18:25
发布于 2020-04-08 03:18:25
30000
代码可运行
举报
文章被收录于专栏:算法修养算法修养
运行总次数:0
代码可运行

题目

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
class Solution {
public:
    int vis[100005];
    bool isAnagram(string s, string t) {
        
        
        for(int i=0;i<s.length();i++)
        {
            vis[s[i]]++;
        }
        
        for(int i=0;i<t.length();i++)
        {
            
            vis[t[i]]--;
            
            if(vis[t[i]]<0)
                return false;
            
        }
        
        for(int i=0;i<100005;i++)
            if(vis[i]!=0)
                return false;
        
        return true;
        
    }
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
String - 242. Valid Anagram
Given two strings s and _t _, write a function to determine if t is an anagram of s.
ppxai
2020/09/23
3330
LeetCode242 Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
用户1665735
2019/02/19
4490
Leetcode 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume the string contains only lowercase alphabets. 判断组成两个字符串
triplebee
2018/01/12
4090
leetcode-242-Valid Anagram
Given two strings s and t , write a function to determine if t is an anagram of s.
chenjx85
2019/03/14
5260
LeetCode 242. Valid Anagram
https://leetcode.com/problems/valid-anagram/
我有一只萌妹子
2022/06/23
1590
C#版[击败99.69%的提交] - Leetcode 242. 有效的同构异形词 - 题解
在线提交: https://leetcode.com/problems/valid-anagram/
Enjoy233
2019/03/05
5720
Leetcode 242. Valid Anagram
版权声明:博客文章都是作者辛苦整理的,转载请注明出处,谢谢! https://blog.csdn.net/Quincuntial/article/details/83031717
Tyan
2019/05/25
3750
LeetCode笔记:242. Valid Anagram
一开始,想了一个现在看来很笨的办法,这道题无非就是要检查两个字符串中的字母是否全部一致,我就遍历其中一个字符串,在每一个字符中,从另一个字符串找到第一个相同的字符,然后删掉字符串中的这个字符,继续遍历,直到有一个字符在另一个字符串中找不到了,说明没有这个字符或者数量少一些,就返回false,如果全部遍历完了都找得到,且另一个字符串也被删完了,那就返回true。这个办法我提交之后,很悲剧的超时了。。。想想也是,时间复杂度是n的平方了,还是很大的。 后来想到了另一个方法,我弄两个int数组,初始各自包含26个"0",用来记录两个字符串中各个字母出现的次数,然后分别遍历两个数组,记录其各个字母出现的次数,最后比较两个int数组是否完全一致就可以了,一遍ac,耗时5ms,打败了85%的提交者,哈哈哈。
Cloudox
2021/11/23
2120
242. 有效的字母异位词
注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。
Regan Yue
2022/09/23
2100
242. 有效的字母异位词
LeetCode 242. 有效的字母异位词
输入: s = “anagram”, t = “nagaram” 输出: true 示例 2:
手撕代码八百里
2020/10/26
3740
leetcode刷题(44)——242. 有效的字母异位词
输入: s = “anagram”, t = “nagaram” 输出: true 示例 2:
老马的编程之旅
2022/06/22
2640
Leetcode 题目解析之 Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
ruochen
2022/01/14
1.4K0
哈希——242.有效的字母异位词
注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。
向着百万年薪努力的小赵
2022/12/02
2130
LeetCode 训练场:242. 有效的字母异位词
1. 题目 242. 有效的字母异位词 2. 描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 示例 1: 输入: s = “anagram”, t = “nagaram” 输出: true 示例 2: 输入: s = “rat”, t = “car” 输出: false 3. 思路 首先长度对比,不同则不是 其次用一个长为 26 的数组来表示各个字符出现的次数 将出现在字符串 s 里的字符个数加 1 出现在字符串 t 里的字符个数减 1 最后判断每个小写
村雨遥
2022/06/15
2100
LeetCode 系列 242. 有效的字母异位词
242. 有效的字母异位词: https://leetcode-cn.com/problems/valid-anagrEND
村雨遥
2020/07/02
2250
242. 有效的字母异位词
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词。
张伦聪zhangluncong
2022/10/26
1650
【LeetCode 242】 关关的刷题日记36 Valid Anagram
关关的刷题日记36 – Leetcode 242. Valid Anagram 题目 Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume the string contain
WZEARW
2018/04/10
7600
画解算法 242-有效的字母异位词
https://leetcode-cn.com/problems/valid-anagram/
灵魂画师牧码
2019/06/27
4590
画解算法 242-有效的字母异位词
【算法千题案例】⚡️每日LeetCode打卡⚡️——63. 有效的字母异位词
注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。
呆呆敲代码的小Y
2021/10/29
2720
【算法千题案例】⚡️每日LeetCode打卡⚡️——63. 有效的字母异位词
LeetCode 242. 有效的字母异位词
1. 题目 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 示例 1: 输入: s = "anagram", t = "nagaram" 输出: true 示例 2: 输入: s = "rat", t = "car" 输出: false 说明: 你可以假设字符串只包含小写字母。 进阶: 如果输入字符串包含 unicode 字符怎么办? 你能否调整你的解法来应对这种情况? 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/prob
Michael阿明
2022/11/26
2310
相关推荐
String - 242. Valid Anagram
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档