当前位置:网站首页>Programmer interview golden code interview question 01.02. determine whether it is character rearrangement
Programmer interview golden code interview question 01.02. determine whether it is character rearrangement
2022-07-22 19:03:00 【yijun009】
Method or number counting
#include <iostream>
#include<string>
using namespace std;
class Solution {
public:
bool CheckPermutation(string s1, string s2) {
int charCount1[100] = {
0 };// All use 0 To initialize
int charCount2[100] = {
0 };// All use 0 To initialize
if (s1.length() != s2.length())
return false;
for(int i = 0; i < int(s1.length()); i++){
charCount1[s1[i] - 'a']++;
charCount2[s2[i] - 'a']++;
}
for (int i = 0; i < 100; i++){
// Here it is. 100 Used to be s1 The length of , Next time, the object and operation should be written clearly
if (abs(charCount1[i] - charCount2[i])>0){
return false;
}
}
return true;
}
};
void main(){
string a = "cuhv"; //C++ Much stricter , Double quotes represent strings 、 Single quotation marks indicate the character
string c = "cuvs";
Solution object_f;
bool b = object_f.CheckPermutation(a,c);
cout << b << endl;
}
They use bit operations in this problem 、hash surface 、 Sort it .
边栏推荐
- [QT source code reuse] simulate the pop-up mode of qcompleter
- PCV、PIL、Pillow安装
- Leetcode:196. delete duplicate email
- PAT乙级1019 数字黑洞 (20 分) (测点错误可能原因)
- 米哈游大量招募新同学,校招提前批最后一天!
- Domestic ngrok achieves intranet penetration
- LeetCode 720. 词典中最长的单词
- Kindling the Darkness: A Practical Low-light Image Enhancer
- LeetCode 654. 最大二叉树
- Leetcode: 184. the highest paid employee in the Department
猜你喜欢
OSI七层网络模型
numpy 求矩阵非零元素的均值
The detailed analysis of the divide () method in BigDecimal takes you into the world of source code
用LaTeX写论文时如何加资助信息
PTA 6-11 find the median of self-determined type element sequence (25 points)
Recursively find the partial sum of simple alternating power series (15 points)
在各類數據庫中隨機查詢n條數據
【链表技巧汇总】141.环形链表(简单)
交叉熵损失函数
JVM-JVM概述
随机推荐
Randomly query n pieces of data in various databases
OSI七层网络模型
Caching-sha2-password problem occurred when connecting mysql8.0
OSI seven layer network model
微信扫网址的二维码,却只显示链接地址,无法跳转到网页的解决办法
Recursively find the partial sum of simple alternating power series (15 points)
LeetCode 116. 填充每个节点的下一个右侧节点指针
Pat class B 1019 digital black hole (20 points) (possible causes of measurement point errors)
Upgrade win10sp1 to the latest version; Qt5.9.6 static compilation (network is valid)
各种技术资料汇总-MYSQL
JVM system optimization
程序员面试金典面试题 01.05. 一次编辑
Problems encountered in using openfeign to realize remote call in Webflux
Exercise 7-4 find out the elements that are not common to two arrays (C language)
【滑动窗口技巧】76. 最小覆盖子串
C language static and extern knowledge points
JVM tuning practice - start from scratch | summary of JVM tuning related to the project
Domestic ngrok achieves intranet penetration
After the project is started, the mapper XML file is loaded circularly
Flink learning notes (VI) Flink's time and window