diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /other/determine_strings_close.rs | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
chore: move cpp and rust code to directory
Diffstat (limited to 'other/determine_strings_close.rs')
-rw-r--r-- | other/determine_strings_close.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/other/determine_strings_close.rs b/other/determine_strings_close.rs new file mode 100644 index 0000000..f293b6d --- /dev/null +++ b/other/determine_strings_close.rs @@ -0,0 +1,25 @@ +struct Solution; + +impl Solution { + pub fn close_strings(word1: String, word2: String) -> bool { + let (mut c1, mut c2) = ([0; 26], [0; 26]); + for &b in word1.as_bytes() { + c1[(b - b'a') as usize] += 1; + } + for &b in word2.as_bytes() { + c2[(b - b'a') as usize] += 1; + } + if (0..26).any(|i| (c1[i] > 0) != (c2[i] > 0)) { + return false; + } + c1.sort_unstable(); + c2.sort_unstable(); + c1 == c2 + } +} + +fn main() { + let word1 = String::from("abc"); + let word2 = String::from("bca"); + print!("{}", Solution::close_strings(word1, word2)); +} |