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. 目录处理工具类 DealWithDir.java

    package com.util; import java.io.File; /** * 目录处理工具类 * */ public class DealWithDir { /** * 新建目录 */ p ...

  2. tomcat内存修改 解决内存溢出异常

    有时候tomcat刚解压完,部署项目后运行会报内存溢出的错误. 原因:项目过大,tomcat内存小. 解决:找到[tomcat]/bin/catlina.bat文件,打开: 在@echo off上面( ...

  3. git tag知多少

    这个命令,其实很有用,类似clearcase中的label,就是给一个版本设置一个标记(标签),方便后期查找特定的版本. tag和commit的sha1那串字符串的关系,不是很大,但是还是要说一下的. ...

  4. Sublime发布Markdown博客

    Sublime发布Markdown博客 下载Sublime插件 插件 按照上面网页中的说明操作 修改插件包中的文件cnblogs.py 第84行,'author'改为自己的邮箱 第86行,'categ ...

  5. Python基础(三)——集合、有序 无序列表、函数、文件操作

    1.Set集合 class set(object): """ set() -> new empty set object set(iterable) -> n ...

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

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

  7. IntelliJ IDEA安装lombok插件

    Settings→Plugins→Browse repositories 输入lom后选择Install Plugin 按照提示重启IDEA   来自为知笔记(Wiz)

  8. bzoj2592: [Usaco2012 Feb]Symmetry

    Description After taking a modern art class, Farmer John has become interested in finding geometric ...

  9. POI按照源单元格设置目标单元格格式

    原文:http://jjw198874.blog.163.com/blog/static/1889845522011102401854234/ POI按照源单元格设置目标单元格格式 poi按照一个源单 ...

  10. [zsh]zsh常用小技巧

    文章来源http://yijiebuyi.com/blog/3154040ae0aa3d352c61a10f2664591e.html shell基础: 查看当前使用shell类型: ->ech ...