1. /*
  2. 思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true。
  3. 记住这个方法
  4. */
  5. if (s.length()!=t.length())
  6. return false;
  7. int[] words = new int[26];
  8. for (int i = 0; i < s.length(); i++) {
  9. words[s.charAt(i)-'a']++;
  10. words[t.charAt(i)-'a']--;
  11. }
  12. for (int i = 0; i < 26; i++) {
  13. if (words[i]!=0)
  14. return false;
  15. }
  16. 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. Calendar类、 System类、 StringBulider类、 包装类

    Calendar类 ​ 概念 ​ java . util . Calendar 日历类,抽象类,在Date类后出现的,替换掉了很多Date类中的方法.该类将所有的可能用到的时间信息封装为静态成员变量. ...

  2. LeetCode 038 Count and Say

    题目要求:Count and Say The count-and-say sequence is the sequence of integers beginning as follows:1, 11 ...

  3. Django 在test.py 中测试文件的配置

    import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTING ...

  4. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  5. 关闭Win10窗口拖动到桌面边缘自动缩放功能

  6. 学习PKI技术【理论+实战】

    1.预备知识 PKI(Public Key Infrastructure)定义 PKI:利用公钥理论和技术建立的提供网络信息安全服务的基础设施.为用户提供所需的密钥和证书管理,用户可以利用PKI平台提 ...

  7. charles功能(三)弱网测试(模拟超慢网速,会导致接口数据返回超时的那种慢)

    模拟超慢网速(会导致接口数据返回超时的那种...) 设置带宽和延迟时间(毫秒) 注:可以根据下图中的翻译体会下导致网络延迟的原因: 然后打开网页回变得非常满

  8. day1(Django)

    1,web项目工作流程 1.1 了解web程序工作流程 1.2 django生命周期   2,django介绍 目的:了解Django框架的作用和特点作用: 简便.快速的开发数据库驱动的网站 Djan ...

  9. day4(编写注册接口)

    1.编写注册接口 1.1 user/urls.py中添加路由 urlpatterns = [    path('register/', views.RegisterView.as_view()),  ...

  10. PyQt(Python+Qt)学习随笔:信号签名中的万能Python类型PyQt_PyObject

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 信号在定义时参数如果使用字符串'PyQt_PyObject'表示参数可以是任何Python类型,这通 ...