/*
思路是判断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. kali查看本机ip

  2. 微信支付万亿日志在Hermes中的实践

    导语 | 微信支付日志系统利用 Hermes 来实现日志的全文检索功能,自从接入以来,日志量持续增长.目前单日入库日志量已经突破万亿级,单集群日入库规模也已经突破了万亿,存储规模达 PB 级.本文将介 ...

  3. PyQt(Python+Qt)学习随笔:QTreeWidgetItem项中列数据的访问方法

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 树型部件QTreeWidget中的QTreeWidgetItem项中可以有多列数据,每列数据可以根据 ...

  4. 题解-Little C Loves 3 III

    Little C Loves 3 III 给定 \(n\) 和序列 \(a_0,a_1,\dots,a_{2^n-1}\) 和 \(b_0,b_1,\dots,b_{2^n-1}\),求序列 \(c_ ...

  5. 惊天秘密!如何在 Flutter 项目中实现操作引导

    不要冒然评价我,你只知道我的名字,却不知道我的故事,你只是听闻我做了什么,却不知我经历过什么. 俗话说得好,产品有三宝,弹窗浮层加引导. 上图截图自我司 App 晓黑板中的口算模块,相信每个 App ...

  6. mac系统下用ssh方式连接git仓库

    1.应用程序-终端,键入命令  ssh-keygen -t rsa -C "xxxxx@xxxxx.com"  ,后面是你的邮箱地址.一直回车,生成密钥. 2.键入  open ~ ...

  7. 博流BL602&BL604开发板介绍

    在2020松山湖论坛上,博流智能科技(南京)有限公司销售副总裁刘占领介绍了基于RISC-V核的低功耗.高可靠Wi-Fi+BLE二合一SoC芯片BL602.主要应用领域包括人工智能与工业互联网,特别是电 ...

  8. get \post 接口代码及断言编写

    post 请求接口 import requests import json url_path = "http://www.baidu.com" data = {"user ...

  9. js下 Day07、DOM案例

    一.折叠菜单 效果图: 功能思路分析: 功能一:数据渲染 \1. 模拟数据,一级数据为数组套对象的形式,二级数据为数组: \2. 先渲染一级数据,然后再嵌套渲染二级数据(map().join('')) ...

  10. [日常摸鱼]Uva11178Morley's Theorem-几何

    题意:给一个$\Delta ABC$,分别做三个角的三等分线相交成$\Delta DEF$,求出$D,E,F$的坐标. 直接根据题意模拟 #include<cstdio> #include ...