【LintCode 简单】158. 两个字符串是变位词
2018-01-25 22:36
477 查看
1.问题描述:
写出一个函数
2.样例:
给出 s =
给出 s =
返回
给出 s =
返回
3.代码:
写出一个函数
anagram(s, t)判断两个字符串是否可以通过改变字母的顺序变成一样的字符串。
2.样例:
给出 s =
"abcd",t=
"dcab",返回
true.
给出 s =
"ab", t =
"ab",
返回
true.
给出 s =
"ab", t =
"ac",
返回
false.
3.代码:
class Solution: """ @param s: The first string @param b: The second string @return true or false """ def anagram(self, s, t): # write your code here l1=list(s) l2=list(t) length1=len(l1) length2=len(l2) if length1!=length2: return False else: for i in range(length1): for j in range(length2): fg=False if l1[i]==l2[j]: l1[i]=0 l2[j]=0 fg=True break if fg==False: return False return True
相关文章推荐
- LintCode-两个字符串是变位词
- [lintcode]两个字符串是变位词
- 两个字符串是否是变位词(直接lintcode敲代码,一次通过,噢耶!)
- 两个字符串是变位词-LintCode
- lintcode-158-两个字符串是变位词
- Lintcode--002(两个字符串是变位词)
- lintCode_两个字符串是变位词
- Lintcode—(1)两个字符串是变位词
- LintCode:两个字符串是变位词
- Lintcode(1)-两个字符串是变位词
- 【LintCode】两个字符串是变位词
- LintCode【简单】53. 翻转字符串 。代码及思路
- 面试题:两个字符串是变位词
- C的一些简单习题(5)--两个字符串比较
- [LintCode]158.两个字符串是变位词(ps:OJ上相同的代码执行时间会差很多吗)
- LintCode 两个字符串是变位词
- LintCode 两个字符串是变位词
- 两个字符串是变位词
- 两个字符串是变位词
- 计算两个字符串之间是否包含的简单方法