0
点赞
收藏
分享

微信扫一扫

LintCode 题目:字符串置换

Sikj_6590 2022-06-29 阅读 77

URL:​​https://www.lintcode.com/problem/string-permutation/description​​

描述

给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换。

置换的意思是,通过改变顺序可以使得两个字符串相等。

 

样例

Example 1:
Input: "abcd", "bcad"
Output: True


Example 2:
Input: "aac", "abc"
Output: False

思路:

只要其中所有的字符相等即可。

在代码段中添加:

int str1[128]={0},str2[128]={0};
int n1 = A.size();
int n2 = B.size();
for (int i = 0; i < n1; i++) {
/* code */
str1[A[i]]++;
}
for (int i = 0; i < n2; i++) {
/* code */
str2[B[i]]++;
}
for(int i=1;i<128;i++){
if(str1[i]==str2[i])
continue;
else
return false;
}
return true;

即可:

LintCode 题目:字符串置换_i++


举报

相关推荐

0 条评论