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: ...
随机推荐
- Dynamics CRM2013/2015 插件注册工具登录后无法显示assembly列表问题的解决办法二
本篇接前面的一篇博文:http://blog.csdn.net/vic0228/article/details/47079717,前篇提供了一种解决方案,将本机系统的语言切换成英文即可,今天再来介绍第 ...
- ROS_Kinetic_24 使用catkin_create_qt_pkg快速创建qt-ros功能包
使用catkin_create_qt_pkg快速创建qt-ros功能包 参考网址: qt_create:http://wiki.ros.org/qt_create qt_ros:https://git ...
- linux中的网络通信指令
1.write write命令通信是一对一的通信,即两个人之间的通信,如上图. 效果图 用法:write <用户名> 2.wall wall指令可将信息发送给每位同意接收公众信息的终端机用 ...
- I/O操作之文件压缩与解压
与文件压缩与解压相关的类在java.util.zip包下 实例 //文件压缩 import java.io.File; import java.io.FileInputStream; import j ...
- (NO.00004)iOS实现打砖块游戏(七):关卡类的实现
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 关卡游戏的精髓都集中在游戏的关卡里,其中包含了游戏的所有要素,至 ...
- 【一天一道LeetCode】#292. Nim Game
一天一道LeetCode 从今天开始,调整规律,不按顺序做,从easy开始! 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 ...
- Android面试之高级篇
结合自己之前去很多大公司的面试经历和自己面别人的一些题,这里做一些总结,Android面试中常见的面试题. 1,Android的Handler运行机制 要解释Handler的运行机制就要讲几个对象:M ...
- 《java入门第一季》之HashSet小案例:获取10个1至20的随机数,要求随机数不能重复
这是基于HashSet集合的唯一性. /* * 编写一个程序,获取10个1至20的随机数,要求随机数不能重复. * * 分析: * A:创建随机数对象 * B:创建一个HashSet集合 ...
- (六十八)使用XMPPFramework登录
按照XMPPFramework的官方样例,应该把登录代码放置在AppDelegate中,并且让注销成为私有方法. XMPPFramework进行登录的步骤如下: ①连接主机,并且发送JID ②如果连接 ...
- python的sys模块
Sys模块函数之多,我只能选取自己认为比较实用的一些函数列在此处.借马云找员工的说法,"找最合适的而不是最天才的",这句话,我个人觉得在很多方面都能适应,学习也不在话下.Sys模块 ...