[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: s = "anagram", t = "nagaram"
Output: true
Example 2:
Input: s = "rat", t = "car"
Output: false
题意:
验证变位词
何谓anagram?

思路:
用int[] map = new int[256]代表一个简化版的HashMap
挨个扫字符串s的每个字符,在map里标注++
挨个扫字符串t的每个字符,在map里标注--
根据valid anagram属性, map里最终应该都该为0。
代码:
class Solution {
public boolean isAnagram(String s, String t) {
if(s.length() != t.length()) return false;
int[] map = new int[256];
for(int i = 0 ; i < s.length(); i++){
map[s.charAt(i)]++;
map[t.charAt(i)]--;
}
for(int i : map){
if(i != 0){
return false;
}
}
return true;
}
}
[leetcode]242. Valid Anagram验证变位词的更多相关文章
- [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] Valid Anagram 验证变位词
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
- 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. 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. For example, s = & ...
- 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 ...
- (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 = &q ...
- 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, ...
随机推荐
- 自己写的jQuery浮动广告插件
效果图: 文件位置摆放: 插件的js代码: $.extend({ pfAdv:function(options){ var defaults={ count:1, startTop:200, star ...
- Ubuntu下Code::Blocks错误
#error This file requires compiler and library support for the ISO C++ 2011 standard. This support i ...
- Python Json序列化与反序列化
在python中,序列化可以理解为:把python的对象编码转换为json格式的字符串,反序列化可以理解为:把json格式字符串解码为python数据对象.在python的标准库中,专门提供了json ...
- cplexJava源码---计算结果
public static class CplexStatus implements Serializable { static final long serialVersionUID = -7367 ...
- 0_Simple__simpleCubemapTexture
立方体纹理贴图 ▶ 源代码.用纹理方法把元素按原顺序从 CUDA3D 数组中取出来,求个相反数放入全局内存,输出. #include <stdio.h> #include "cu ...
- sqoop2的使用测试
查看现有link sqoop:000> show link+-----------+------------------------+---------+| Name | Co ...
- cmd查看电脑是32位还是64位
代码如下 @echo off if "%PROCESSOR_ARCHITECTURE%" == "AMD64" ( echo OS is 64bit) EL ...
- clip-path的任意元素的碎片拼接动效
看了张大神的这篇文章后自己写的,兼容性不好clip-path要加-webkit- css #test img{position: absolute;} .active .clip{ will-chan ...
- Vue2.0中v-for迭代语法变化(key、index)
语法发生了变化:http://blog.csdn.net/sinat_35512245/article/details/53966788 新数组语法 value in arr (value, inde ...
- UI5-文档-4.17-Fragment Callbacks
现在我们已经集成了对话框,是时候添加一些用户交互了.用户肯定希望在某个时候再次关闭对话框,因此我们添加一个按钮来关闭对话框并分配一个事件处理程序. Preview The dialog now has ...