LintCode Two Strings Are Anagrams
1. 把string变为char数组
2. 排序Arrays.sort()
public class Solution {
/**
* @param s: The first string
* @param b: The second string
* @return true or false
*/
public boolean anagram(String s, String t) {
if(s == null || t == null) return false;
if(s.length() != t.length()) return false;
char[] arrs = s.toCharArray();
char[] arrt = t.toCharArray();
Arrays.sort(arrs);
Arrays.sort(arrt);
boolean flag = true;
for(int i = 0; i < arrs.length; i++){
if(arrs[i] != arrt[i]){
flag = false;
}
}
return flag;// write your code here
}
};
LintCode Two Strings Are Anagrams的更多相关文章
- Two Strings Are Anagrams
Write a method anagram(s,t) to decide if two strings are anagrams or not. 判断两个字符串里的字符是否相同,也就是是否能够通过改 ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- [LeetCode] Anagrams 错位词
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...
- Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- LeetCode-Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- 【Leetcode】【Medium】Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- [LeetCode]题解(python):049-Groups Anagrams
题目来源 https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For ...
- 49. Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
- LeetCode49 Group Anagrams
Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...
随机推荐
- 通过Navicat for MySQL远程连接的时候报错mysql 1130
1130 重装数据库 解决这个问题
- 基于H5的移动端开发,window.location.href在IOS系统无法触发问题
最近负责公司的微信公众号开发项目,基于H5进行开发,某些页面window.location.href在Android机上能正常运行而IOS系统上无法运行,导致无法重定向到指定页面,查了好久终于找到方法 ...
- DotNetBar for Windows Forms 11.8.0.8冰河之刃重打包版
关于 DotNetBar for Windows Forms 11.8.0.8_冰河之刃重打包版 基于 官方原版的安装包 + http://www.cnblogs.com/tracky 提供的补丁DL ...
- leetcode日记 Combination sum IV
题目: Given an integer array with all positive numbers and no duplicates, find the number of possible ...
- 【转】Linux下如何清除系统日志
使用过Windows的人都知道,在使用windows系统的过程中系统会变得越来越慢.而对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然系统将会变得越来越大,越来越迟钝!window ...
- jQuery -- DOM节点的操作
DOM 操作的分类: dom core: getElementById() getElementsByTagName() getAttribute() setAttribute() html-dom ...
- Xcode开发小问题集锦
Q:用Xcode 6 创建的工程在iOS 7的设备上运行时上下部均会出现黑色的区域且应用不能全屏运行. A:Targets -> General -> App Icons and Laun ...
- iOS开发一个用户登录注册模块需要解决的坑
最近和另外一位同事负责公司登录和用户中心模块的开发工作,开发周期计划两周,减去和产品和接口的协调时间,再减去由于原型图和接口的问题,导致强迫症纠结症状高发,情绪不稳定耗费的时间,能在两周基本完成也算是 ...
- css:writing-mode属性
writing-mode属性 实现文字垂直排版 下面是css3语法: /* 关键字值 */ writing-mode: horizontal-tb; /* 默认值 */ writing-mode: v ...
- 在linux使用make编译ArduPilot for Pixhawk/PX4 ArduPilot 编译环境搭建
Building ArduPilot for Pixhawk/PX4 on Linux with Make 使用Make编译 ArduPilot for Pixhawk 2, Pixhawk and ...