(easy)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 = "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的更多相关文章
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 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 ...
- [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: ...
- 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 ...
- [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: ...
- 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 ...
- 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, ...
- 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 = & ...
- 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 ...
随机推荐
- python input() 与 raw_input()
使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时: input返回的是数值类型,如int,floatraw_inpo ...
- 手机App开发
/* * 登录:输入 */ public void login(String user, String pwd, TextHttpResponseHandler responsehandler) { ...
- 自动扫描FTP文件工具类 ScanFtp.java
package com.util; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ja ...
- Debian 环境下安装Tomcat记录
1.安装JAVA运行环境 Debian默认带了OpenJDK,有人说不好用,我没有验证就从ORACLE官网上下载了最新的JDK安装包,直接解压并设置环境变量就行了: # tar zxvf jdk-8u ...
- C# Color Table颜色对照表
.AliceBlue 240,248,255 .LightSalmon 255,160,122 .AntiqueWhite 250,235,215 .LightSeaGreen 32,178,170 ...
- 【linux】linux如何进入单人维护模式修改root密码
- IntelliJ IDEA安装AngularJS插件
Settings→Plugins→Install JetBrains plugins... 输入an后选择AngularJS,然后点击Install进行安装 按照提示重启IDEA 下图为插件管理窗口, ...
- 借助LVS+Keepalived通过DR模式实现负载均衡
1.测试环境4台server,全部初始化一下,该关的关了 # vim /etc/hosts 192.168.1.101 lvs-master DIP 192.168.1.102 lvs-slave D ...
- c++的历史-异常
1.异常出现的目的 在c++语言的设计和演化中,Bjarne Stroustrup说过异常的设计假定如下情况: 基本上是为了处理错误 与函数定义相比,异常处理是很少的 与函数调用相比,异常出现的频率较 ...
- Env:Winmanager插件使用
转自:http://www.cnblogs.com/feichexia/archive/2012/11/06/vim_WinManager.html 1.准备winmanger插件,从下面网址下即可: ...