/*
思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true。
记住这个方法
*/
if (s.length()!=t.length())
return false;
int[] words = new int[26];
for (int i = 0; i < s.length(); i++) {
words[s.charAt(i)-'a']++;
words[t.charAt(i)-'a']--;
}
for (int i = 0; i < 26; i++) {
if (words[i]!=0)
return false;
}
return true;

记住这种判断两个字符是不是重排列的方法,就是判断26个字母是不是出现次数相同。

当与字符相关问题是,要记得考虑26字母hashtable

[leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列的更多相关文章

  1. Leetcode 242 Valid Anagram 字符串处理

    字符串s和字符串t是否异构,就是统计两个字符串的a-z的字符数量是否一值 class Solution { public: bool isAnagram(string s, string t) { ] ...

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

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

  3. 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 = & ...

  4. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  5. LeetCode 242 Valid Anagram 解题报告

    题目要求 Given two strings s and t , write a function to determine if t is an anagram of s. 题目分析及思路 给出两个 ...

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

  7. [google面试CTCI] 1-4.判断两个字符串是否由相同字符组成

    [字符串与数组] Q:Write a method to decide if two strings are anagrams or not 题目:写一个算法来判断两个字符串是否为换位字符串.(换位字 ...

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

  9. LeetCode 242 Valid Anagram

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

随机推荐

  1. LeetCode 004 Median of Two Sorted Arrays

    题目描述:Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. F ...

  2. rest-framework:认证组件

    一 认证简介: 只有认证通过的用户才能访问指定的url地址,比如:查询课程信息,需要登录之后才能查看,没有登录,就不能查看,这时候需要用到认证组件 二 局部使用 models.py class Use ...

  3. UUID介绍与生成的方法

    什么是UUID? UUID是Universally Unique Identifier的缩写,它是在一定的范围内(从特定的名字空间到全球)唯一的机器生成的标识符.UUID具有以下涵义: 经由一定的算法 ...

  4. Java高薪训练营(对标阿里P7,限时分享)

    某钩Java高薪训练营(部分,持续更新) 下载地址 防止网盘和谐多次补链修改,公众号回复「训练营」自提.

  5. 【C++】C++之Lambda表达式

    目录 一.前言 二.Lambda表达式格式说明 2.1 完整的Lambda表达式格式 2.2 常见的Lambda表达式格式 2.3 lambda 表达式捕获列表 三.示例 3.1 STL的sort函数 ...

  6. moviepy音视频剪辑:使用autoTrack、manual_tracking+headblur实现半自动追踪人脸打马赛克

    一.引言 在<moviepy1.03音视频剪辑:使用manual_tracking和headblur实现追踪人脸打马赛克>介绍了使用手动跟踪跟踪人脸移动轨迹和使用headblur对人脸进行 ...

  7. 关于建立老猿Python研学群的公告

    3个月前有人建议老猿建立一个Python学习交流群,老猿自己学习Python也没多久,因此没有考虑这个事情,最近又有几个朋友在请我建立这样一个群,犹豫再三,老猿决定还是答应了,因为最近关注老猿Pyth ...

  8. HashMap稍微详细的理解

    此文章用来记录hashmap的一些特点(在学习中的所了解的,如有不足,请指正) 什么是hash表 概念 先来一段百度百科的的解释 散列表(Hash table,也叫哈希表),是根据关键码值(Key v ...

  9. CNVD漏洞证书(1)

    之前申请了CNVD原创漏洞,踩了坑,记录一下 有很多师傅写过相关的文章: https://blog.csdn.net/qq1124794084/article/details/82657840 htt ...

  10. Scrum 冲刺 第一篇

    Scrum 冲刺 第一篇 每个成员认领的任务 人员 任务 周立 后台登录注册模块 邓富荣 后台首页模块 钟俊豪 博客圈模块 黄清山 个人界面模块 郑焕 首页以及博客圈界面 黄梓浩 个人界面以及登录注册 ...