[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, ...
随机推荐
- 【转】SQL模糊查询
在进行数据库查询时,有完整查询和模糊查询之分. 一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1,% :表示任 ...
- 【基础知识六】支持向量机SVM
开发库: libsvm, liblinear GitHub地址 SVM难点:核函数选择 一.基本问题 找到约束参数ω和b,支持向量到(分隔)超平面的距离最大:此时的分隔超平面称为“最优超平面 ...
- Determining IP information for eth0...failed 错误解决
问题描述:虚拟机使用wget命令上网,执行service network restart后出现如下错误Determining IP information for eth0...failed解决办法: ...
- 软件测试——Peer Review(简介)
1. 同行评审的种类和对象 同行评审活动的关注点应该是工作产品中的缺陷,而不应该是工作产品的作者或者生产者,管理者也不应使用同行评审的结果去评价个人的行为. 同行评审的分类有很多种,自从IBM的Fag ...
- uva-185-暴力枚举
请相信,这是一道水题,读了一周的题意 题意: 题目里面描述的那三个条件可以直接无视,关于罗马数字只要知道一个规则即可,映射如下 I 1 V 5X 10 L 50C 100 D 50 ...
- configparser 文件的生成和读写
# configparser 生成 import configparser config = configparser.ConfigParser() config[DEFUALT] = {'Serve ...
- delegate() 事件绑定 事件委托
定义和用法 delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数. 使用 delegate() 方法的事件处理程序适用于当前或未来 ...
- 使用JS获取当前地理位置方法汇总
使用JS获取当前地理位置方法汇总 投稿:hebedich 字体:[增加 减小] 类型:转载 时间:2014-12-18我要评论 这篇文章主要介绍了使用JS获取当前地理位置方法汇总,需要的朋友可以参考下 ...
- JVM gc介绍
Java语言出来之前,大家都在拼命的写C或者C++的程序,而此时存在一个很大的矛盾,C++等语言创建对象要不断的去开辟空间,不用的时候有需要不断的去释放控件,既要写构造函数,又要写析构函数,很多时候都 ...
- mongodb基础学习7-备份与恢复
下面来讲讲mongodb的备份与恢复 备份可以备份为二进制格式,如果是用于数据交换,可以备份成json或cvs格式 导入/导出可以操作的是本地的mongodb服务器,也可以是远程的. 所以,都有如下通 ...