[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, ...
随机推荐
- H3C的DHCP中继配置命令
dhcp enable命令用来使能DHCP服务 dhcp relay information enable 命令用来配置DHCP中继支持Option 82功能 缺省情况下,DHCP中继不支持Optio ...
- php multicast多播实现详解
什么是多播? 网络中存在3中传播形式,单播,广播,多播. 1. 单播 : 就是1->1 2. 广播 : 1->多(广播域内) 3. 多播 : 1->组(一组ip) 1 2 3 4 5 ...
- 编译遇到make mrmroper问题
]: Entering directory `/home/share/project/ql-ol-sdk/ql-ol-kernel' ]: Entering directory `/home/shar ...
- java实现远程控制
屏幕监控: Robot robot = new Robot();Dimension d = Toolkit.getDefaultToolkit().getScreenSize();image = ro ...
- ORA:01745 无效的主机 绑定变量名
原因是:mybatis中的mapping映射时,sql语句中忘了加逗号,且逗号处有换行
- HTML|CSS之HTML常用标签
知识内容: 1.标签 2.head内标签 3.body内常用标签 注:本人使用的HTML为HTML5 一.标签 1.标签格式 标签的语法: <标签名 属性1=“属性值1” 属性2=“属性值2”… ...
- mavenProfile文件配置和简单入门
1什么是MavenProfile 在我们平常的java开发中,会经常使用到很多配制文件(xxx.properties,xxx.xml),而当我们在本地开发(dev),测试环境测试(test),线上生产 ...
- springboot实现国际化
1.编写配置文件 2.在application.properties中添加 i18n指的是国际化所在包名 3.实现国际化的接口 4.在配置类中
- 免费json API
免费json API http://www.bejson.com/knownjson/webInterface/
- xml 创建 和 处理 及其修改
#创建xml import xml.etree.ElementTree as ET new_xml = ET.Element('namelist') personinfo = ET.SubElemen ...