LeetCode之旅(13)-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.
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case? ##
思路分析:
题意是判断两个字符串包含的字符是不是相同,这样的问题,可以通过排序来简化 ,这个题目和前面的一个一片博客的题目(判断数组是否包含重复的元素)很相似,可以对照着
leetcode之旅(8)-Contains Duplicate
代码:
public class Solution {
public boolean isAnagram(String s, String t) {
char[] oneArray = s.toCharArray();
char[] twoArray = t.toCharArray();
Arrays.sort(oneArray);
Arrays.sort(twoArray);
int oneLength = oneArray.length;
int twoLength = twoArray.length;
if(oneLength ==twoLength){
for(int i = 0;i < oneLength;i++){
if(oneArray[i] == twoArray[i]){
}else{
return false;
}
}
}else{
return false;
}
return true;
}
}
LeetCode之旅(13)-Valid Anagram的更多相关文章
- 【leetcode❤python】242. Valid Anagram
class Solution(object): def isAnagram(self, s, t): if sorted(list(s.lower()))==sorted(list ...
- [LeetCode&Python] Problem 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 ...
- leetcdoe Valid Anagram
题目连接 https://leetcode.com/problems/valid-anagram/ Valid Anagram Description Given two strings s and ...
- leetcode面试准备:Valid Anagram
leetcode面试准备:Valid Anagram 1 题目 Given two strings s and t, write a function to determine if t is an ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 【LeetCode】242. Valid Anagram (2 solutions)
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...
- [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.3、Android Studio的CPU Monitor
Android Monitor包含一个CPU Monitor,可以让你非常方便的监测你的应用的CPU的使用.它显示试试的CPU使用. 在CPU Monitor显示正在运行的应用 1. 打开一个项目 2 ...
- javascript之DOM对象
document方法 document.createElement(Tag) :创建一个html标签对象 document.getElementById(ID) :获得指定ID值的对象 documen ...
- Android简易实战教程--第十五话《在外部存储中读写文件》
第七话里面介绍了在内部存储读写文件 点击打开链接. 这样有一个比较打的问题,假设系统内存不够用,杀本应用无法执行,或者本应用被用户卸载重新安装后.以前保存的用户名和密码都不会得到回显.所以,有必要注意 ...
- I/O操作之文件压缩与解压
与文件压缩与解压相关的类在java.util.zip包下 实例 //文件压缩 import java.io.File; import java.io.FileInputStream; import j ...
- hashmap 循环取出所有值 取出特定的值 两种方法
//第一种 Iterator menus = menu.iterator(); while(menus.hasNext()) { Map userMap = (Map) menus.next(); S ...
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(七):弹出地鼠
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...
- Android进阶(四)一个APP引发的思索之ArrayList的add总是添加相同的值
解决"ArrayList的add总是添加相同的值"问题 前言 最近在写一个小的Android APP,在用ArrayList的add时,总是出现添加相同值的现象.如下图所示: 错误 ...
- (四十七)Quartz2D引擎初步
Quartz2D是跨平台的,同时支持iOS与Mac. 支持圆型裁剪,可以实现圆形头像等功能,也支持手势解锁.折线图等的制作. 对于复杂的UI界面,还可以通过Quartz2D将控件内部的结构画出来,可用 ...
- ibatis 数据库时间 插入数据
<insert id="insert" parameterClass="ToDoBar" > <selectKey resultCla ...
- 网站开发进阶(三十二)HTML5之FileReader的使用
HTML5之FileReader的使用 HTML5定义了FileReader作为文件API的重要成员用于读取文件,根据W3C的定义,FileReader接口提供了读取文件的方法和包含读取结果的事件模型 ...