/*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.*/
public static boolean isAnagram(String s, String t) {
int[] ch1 = new int[26];
char[] cha1 = s.toCharArray();
char[] cha2 = t.toCharArray();
if (cha1.length != cha2.length)
return false;
for (int i = 0; i < cha1.length; i++) {
int temp = cha1[i] - 97;
ch1[temp]++;
}
for (int i = 0; i < cha2.length; i++) {
int temp = cha2[i] - 97;
ch1[temp]--;
}
for (int i : ch1) {
if (i != 0)
return false;
}
return true;
}
}

isAnagram的更多相关文章

  1. [LeetCode] Valid Anagram 验证变位词

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

  2. Leetcode分类刷题答案&心得

    Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...

  3. 全部leetcode题目解答(不含带锁)

    (记忆线:当时一刷完是1-205. 二刷88道.下次更新记得标记不能bug-free的原因.)   88-------------Perfect Squares(完美平方数.给一个整数,求出用平方数来 ...

  4. Leetcode Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  5. 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 ...

  6. Continue To DO!

    (1)Valid Anagram 解题思路: 使用一个数组,首先遍历S相应位置加1,然后遍历T,判断此时如果相应位置为零返回FALSE,否则就减一.T遍历完毕后返回true. 代码如下: public ...

  7. 【09_242】Valid Anagram

    Valid Anagram My Submissions Question Total Accepted: 43694 Total Submissions: 111615 Difficulty: Ea ...

  8. Valid Anagram

    class Solution { public: bool isAnagram(string s, string t) { if(t=="") return s=="&q ...

  9. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

随机推荐

  1. es6新特性

    变量-------------------------- let, const:必须直接给一个变量赋值.注意,对象的属性或数组成员还是可以改变的. const MY_OBJECT = {some: 1 ...

  2. Intellij Idea 12 生成serialVersionUID的方法

    默认情况下Intellij IDEA是关闭了继承了java.io.Serializable的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需 ...

  3. apache 2.4 配置多个站点

    1.打开\Apache24\conf\httpd.conf 查找conf/extra/httpd-vhosts.conf  去掉前面的#号,一般是去掉的 2.在httpd.conf 中查找Requir ...

  4. EditText使用详解-包含很多教程上看不到的功能演示

    写道 标题有点大,说是详解,其实就是对EditText的一些常用功能的介绍,包括密码框,电话框,空白提示文字等等的讲解,尽量的介绍详细一点,也就是所谓的详解了..呵呵 广告一下我的应用“我团”,最新1 ...

  5. Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法

    Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法 昨天在开发的时候遇到个小问题,就是如何将Grid的内容与Form一起发送到服务器端.默认情况下,表单(F ...

  6. 【XML配置文件读取】使用jdom读取XML配置文件信息

    在项目中我们经常需要将配置信息写在配置文件中,而XML配置文件是常用的格式. 下面将介绍如何通过jdom来读取xml配置文件信息. 配置文件信息 <?xml version="1.0& ...

  7. 如何重装air

    参考这里 很多年没有装过系统了,手贱用xxcleaner清理了下,好吧,我觉得只能重装了,直接贴过程吧 ,开机同时command+R,进入菜单 ,抹掉磁盘 ,重启,等在线更新(看各位运气了,网速好的话 ...

  8. SQL执行效率和性能测试方法

    对于做管理系统和分析系统的程序员,复杂SQL语句是不可避免的,面对海量数据,有时候经过优化的某一条语句,可以提高执行效率和整体运行性能.如何选择SQL语句,本文提供了两种方法,分别对多条SQL进行量化 ...

  9. IO操作 第一篇 学习(转载)

    问题8:如何使用通配符搜索指定目录内的所有文件: 解决方案: 使用DirectoryInfo.GetFiles方法的重载版本,它可以接受一个过滤表达式,返回FileInfo数组,另外它的参数还可以指定 ...

  10. 不用配置tnsnames.ora,直接通过PL/SQL访问远程数据库