暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122
  1. #[cfg(test)]
  2. mod tests {
  3. #[test]
  4. fn it_works() {
  5. assert_eq!(2 + 2, 4);
  6. }
  7. }
  8. pub fn hamming_distance(s1: &str, s2: &str) -> Result<usize, String> {
  9. //Check if the given Strings are of different length
  10. if s1.len() != s2.len() {
  11. return Err("Strings must be of equal length!".to_string());
  12. }
  13. let mut dist: usize = 0;
  14. for i in 0..s1.len() {
  15. //Compare each character of the Strings
  16. if s1.chars().nth(i) != s2.chars().nth(i) {
  17. //If they don't match, increment hamming distance
  18. dist += 1
  19. }
  20. }
  21. Ok(dist)
  22. }