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.

解法:英文颠倒词,只要两个单词中,英文字母出现的次数相等即可。

代码如下:

public class Solution {
public boolean isAnagram(String s, String t) {
int []map=new int[26];
char[] c1=s.toCharArray();
for(char t1:c1){
map[t1-'a']++;
}
char[]c2=t.toCharArray();
for(char t2:c2){
map[t2-'a']--;
}
for(int i=0;i<26;i++){
if(map[i]!=0)
return false;
}
return true;
}
}

  

运行结果:

(easy)LeetCode 242.Valid Anagram的更多相关文章

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

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

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

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

  4. 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 = &q ...

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

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

  7. Java [Leetcode 242]Valid Anagram

    题目描述: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...

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

  9. Leetcode 242 Valid Anagram pytyhon

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

随机推荐

  1. 删除文件夹工具类 DeleteFolder.java

    package com.util; import java.io.File; /** * 删除文件夹 * @createTime DSC 20, 2010 15:38 * @version 2.0 * ...

  2. ORACLE 表函数实现

    1.创建表对象类型. 在Oracle中想要返回表对象,必须自定义一个表类型,如下所示: create or replace type t_table is table of number; 上面的类型 ...

  3. MySQL5.7.13源码编译安装指南(转)

    系统 CenterOs 6.5 1.安装依赖包(cmake make gcc等,其实好多都有了,不需要更新,为了防止世界被破坏,就装下) yum install gcc gcc-c++ -yyum i ...

  4. java单例模式和双例模式

    今天朋友找我给做道题,双例模式,我是没听说过,都说是单例模式和多例模式, 也不知道双例模式什么时候用,就简单写了一个案例,不知道对不对,个人感觉蛮对的,双例就是单例+单例,废话不说了!!!! /* * ...

  5. CSS3中样式顺序

    .box{ /*1*/ background: yellow; /*2*/ background: radial-gradient(ellise, yellow, red); } 就以上样式1和2的顺 ...

  6. asp.net get App_Data 目录几种方法 path

    方法一 //ASP.NET MVC1 -> MVC3 string path = HttpContext.Current.Server.MapPath("~/App_Data/some ...

  7. 如何设置DNS的SPF记录

    如何设置DNS的SPF记录 Introduction SPF的完整意思为 "Sender Policy Framework".翻译过来就是发送方策略框架,是一项跟 DNS 相关的技 ...

  8. ie浏览器的渲染原理

    IE下载或者渲染顺序大致如下: IE下载的顺序是从上到下,渲染的顺序也是从上到下,下载和渲染是同时进行的. 在渲染到页面的某一部分时,其上面的所有部分都已经下载完成(但并不是说所有相关联的元素都已经下 ...

  9. sealed修饰符

    sealed(C# 参考) 当对一个类应用 sealed 修饰符时,此修饰符会阻止其他类从该类继承. 在下面的示例中,类 B 从类 A 继承,但是任何类都不能从类 B 继承. class A {} s ...

  10. 黄聪:wordpress更新失败‘C:\Windows\TEMP/wordpress.tmp’,更换临时保存路径的解决办法

    1.如果可劲进入远程桌面,则给C:\WINDOWS\TEMP目录设置IIS访问权限. 2.虚拟机的方法:首先用FTP软件在网页空间wp-content目录中新建一个[tmp]目录,然后在wp-conf ...