20240824 finished.

This commit is contained in:
jackfiled 2024-08-24 11:52:03 +08:00
parent 3ea818ef10
commit 3f326e3185
4 changed files with 62 additions and 12 deletions

View File

@ -1,11 +0,0 @@
#!/bin/sh
set -e
time=$(date "+%Y%m%d")
message="$time Finished"
git add -A
git commit -m "$message"
git push

20
justfile Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env just --justfile
build:
cargo build --release
test:
cargo test
commit:
#!/usr/bin/env bash
set -euxo pipefail
time=$(date "+%Y%m%d")
message="$time finished."
git add -A
git commit -m "$message"
git push
pull id: build
./target/release/leetcode-rust {{id}}

View File

@ -214,4 +214,5 @@ mod p552_student_attendance_record_ii;
mod p3154_find_number_of_ways_to_reach_the_k_th_stair;
mod p3007_maximum_number_that_sum_of_the_prices_is_less_than_or_equal_to_k;
mod p3133_minimum_array_end;
mod p3145_find_products_of_elements_of_big_array;
mod p3145_find_products_of_elements_of_big_array;
mod p3146_permutation_difference_between_two_strings;

View File

@ -0,0 +1,40 @@
/**
* [3146] Permutation Difference between Two Strings
*/
pub struct Solution {}
// submission codes start here
use std::collections::HashMap;
impl Solution {
pub fn find_permutation_difference(s: String, t: String) -> i32 {
let mut map = HashMap::new();
for (i, c) in s.chars().enumerate() {
map.insert(c, i as i32);
}
let mut result = 0;
for (i, c) in t.chars().enumerate() {
let target = map.get(&c).unwrap();
result += (i as i32 - *target).abs()
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_3146() {
assert_eq!(2, Solution::find_permutation_difference("abc".to_owned(), "bac".to_owned()));
}
}