From 9bcda808e56ce0141709c17adeef0689636ff091 Mon Sep 17 00:00:00 2001 From: mhrooz Date: Wed, 29 Nov 2023 23:19:30 +0100 Subject: [PATCH] 1657 a simple sorting problem --- .gitignore | 1 + 1657-231130/main.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 1657-231130/main.cpp diff --git a/.gitignore b/.gitignore index 3126d03..b7ba0b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ main .vscode +main.dSYM \ No newline at end of file diff --git a/1657-231130/main.cpp b/1657-231130/main.cpp new file mode 100644 index 0000000..ac069a9 --- /dev/null +++ b/1657-231130/main.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; + +class Solution{ + public: + bool closeStrings(string word1, string word2){ + if(word1.length()!=word2.length()) return false; + const int char_nums = 26; + int word1_chars[char_nums] = {}; + int word2_chars[char_nums] = {}; + for(int i = 0 ; i < word1.length();i++){ + int word1_char = word1[i] - 'a'; + int word2_char = word2[i] - 'a'; + word1_chars[word1_char]++; + word2_chars[word2_char]++; + } + for(int i = 0 ; i