242. 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?
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
[一句话思路]:
字母就用26,字符用256
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
[复杂度]:Time complexity: O(n) Space complexity: O(n)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[关键模板化代码]:
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
49. Group Anagrams 打碎
[代码风格] :
class Solution {
public boolean isAnagram(String s, String t) {
//ini
int[] chars = new int[26];
//for loop, +s, -t
for (int i = 0; i < s.length(); i++) {
chars[s.charAt(i) - 'a']++;
}
for (int j = 0; j < t.length(); j++) {
chars[t.charAt(j) - 'a']--;
}
//return i != 0
for (int i = 0; i < chars.length; i++) {
if (chars[i] != 0) return false;
}
return true;
}
}
242. Valid Anagram 两个串的最基础版本的更多相关文章
- 242. Valid Anagram(C++)
242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of 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 (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: ...
- [leetcode]242. Valid Anagram判断两个字符串是不是包含相同字符的重排列
/* 思路是判断26个字符在两个字符串中出现的次数是不是都一样,如果一样就返回true. 记住这个方法 */ if (s.length()!=t.length()) return false; int ...
- 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 ...
- 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 = & ...
随机推荐
- 18 Python 模块引入
Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python 代码段. 把相关的代码 ...
- Eclipse插件开发_学习_00_资源帖
一.官方资料 1.eclipse api 2.GEF Developer's Guide 二. 精选资料 1.开发 Eclipse 插件 2.Eclipse, RCP, Plugin and OSGi ...
- 三目运算符与if else的运行效率
两者的效率比较: 当比较次数较少时,效率一样: 当比较次数较多时,发现ifelse的速度更快,应该是其汇编指令更少的原因. if else的汇编代码如下: 三目运算符代码如下:
- linux monitor and maintanence
@cacti 1.install epel extends source 2.install lamp use yum method yum install -y httpd php php-mysq ...
- 详细说明svn分支与合并,以及实例
详细说明svn分支与合并,以及实例 一,svn分支与合并有什么用? 作程序的,对svn在熟悉不过了,但对svn分支熟悉的,我想并不多.因为一般情况下,是用不着svn分支的,其实也没有那个必要.下面我例 ...
- 机器学习(六)— logistic回归
最近一直在看机器学习相关的算法,今天学习logistic回归,在对算法进行了简单分析编程实现之后,通过实例进行验证. 一 logistic概述 个人理解的回归就是发现变量之间的关系,也就是求回归系数, ...
- swing之JDialog
package canying; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java ...
- npm install -d
nodejs Error: Cannot find module 'xxx'错误 解决方案: 确定package.json里有添加相应的依赖配置 使用npm install -d 可以自动配置pack ...
- AngularJs出现错误Error: [ng:areq]
1.没有对应的控制器 2.有控制器但是路径没有配对
- 5.7 Windows常用网络命令
5.7 Windows常用网络命令 •ping •netstat •winipcfg/ipconfig •tracert •route 5.7.1 ping命令 •功能 –它是用来检查网络是否通畅或者 ...