Skip to content

Commit 6231938

Browse files
committed
feat: add digit_neighbors
1 parent 4abe20b commit 6231938

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

open_the_lock/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
pub struct Solution {}
22

33
impl Solution {
4-
pub fn open_lock(deadends: Vec<String>, target: String) -> i32 {}
4+
fn digit_neighbors(n: u8) -> (u8, u8) {
5+
((n + 9) % 10, (n + 11) % 10)
6+
}
7+
8+
pub fn open_lock(deadends: Vec<String>, target: String) -> i32 {
9+
1
10+
}
511
}
612

713
#[cfg(test)]
814
mod tests {
915
use super::*;
1016

17+
#[test]
18+
fn test_digit_neighbors() {
19+
assert_eq!(Solution::digit_neighbors(0), (9, 1));
20+
assert_eq!(Solution::digit_neighbors(9), (8, 0));
21+
for n in 1..9 {
22+
assert_eq!(Solution::digit_neighbors(n), (n - 1, n + 1));
23+
}
24+
}
25+
1126
#[test]
1227
fn example_1() {
1328
let deadends = ["0201", "0101", "0102", "1212", "2002"];

0 commit comments

Comments
 (0)