Medium
,String
,Hash Table
,Sorting
1657. Determine if Two Strings Are Close
Two strings are considered close if you can attain one from the other using the following operations:
For example, abcde -> aecdb
For example, aacabb -> bbcbaa (all
a
's turn intob
's, and allb
's turn intoa
's)
You can use the operations on either string as many times as necessary.
Given two strings, word1
and word2
, return true
if word1
and word2
are close, and false
otherwise.
Example 1:
Apply Operation 1:
"abc" -> "acb"
Apply Operation 1:
"acb" -> "bca"
Example 2:
Example 3:
Apply Operation 1:
"cabbba" -> "caabbb"
Apply Operation 2:
"caabbb" -> "baaccc"
Apply Operation 2:
"baaccc" -> "abbccc"
Constraints:
word1.length
, word2.length
<= 105word1
and word2
contain only lowercase English letters.Kobe Dec 2, 2022
玉山 Dec 2, 2022
順哥:就char set要一樣,個數分布要一樣。
感謝順哥給的提示,感恩順哥讚嘆順哥。
Marsgoat Dec 2, 2022