pub fn zigzag_conversion(s: String, n_rows: i32, alg: Option<Algorithm>) -> String
Expand description

Z 字形变换

可以通过第三个参数选择要使用的算法

Arguments

  • s - 等待变换的字符串
  • n_rows - 变换后的行数
use leetcode_rust::problems_cn::p000_0xx::p000_006::zigzag_conversion;
let mut result_value = zigzag_conversion(String::from("PAYPALISHIRING"), 1, None);
assert_eq!(result_value, String::from("PAYPALISHIRING"));
result_value = zigzag_conversion(String::from("PAYPALISHIRING"), 2, None);
assert_eq!(result_value, String::from("PYAIHRNAPLSIIG"));
result_value = zigzag_conversion(String::from("PAYPALISHIRING"), 3, None);
assert_eq!(result_value, String::from("PAHNAPLSIIGYIR"));