MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / image_smoother

Function image_smoother

661-image-smoother.rs:1–57  ·  view source on GitHub ↗
(img: Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

1pub fn image_smoother(img: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
2 let mut ret = vec![];
3 for i in 0..img.len() {
4 let mut tmp = vec![];
5 let mut tmp_sum = 0;
6 let mut tmp_count = 0;
7 for j in 0..img[0].len() {
8 {
9 {
10 tmp_sum += img[i][j];
11 tmp_count += 1
12 }
13 if j > 0 {
14 tmp_sum += img[i][j-1];
15 tmp_count += 1
16 }
17 if j + 1 < img[0].len() {
18 tmp_sum += img[i][j+1];
19 tmp_count += 1
20 }
21 }
22 if i > 0 {
23 {
24 tmp_sum += img[i-1][j];
25 tmp_count += 1
26 }
27 if j > 0 {
28 tmp_sum += img[i-1][j-1];
29 tmp_count += 1
30 }
31 if j + 1 < img[0].len() {
32 tmp_sum += img[i-1][j+1];
33 tmp_count += 1
34 }
35 }
36 if i + 1 < img.len() {
37 {
38 tmp_sum += img[i+1][j];
39 tmp_count += 1
40 }
41 if j > 0 {
42 tmp_sum += img[i+1][j-1];
43 tmp_count += 1
44 }
45 if j + 1 < img[0].len() {
46 tmp_sum += img[i+1][j+1];
47 tmp_count += 1
48 }
49 }
50 tmp.push((tmp_sum as f64 / tmp_count as f64).floor() as i32);
51 tmp_sum = 0;
52 tmp_count = 0;
53 }
54 ret.push(tmp);
55 }
56 ret
57}
58
59fn main() {
60 let img = vec![vec![1,1,1], vec![1,0,1], vec![1,1,1]];

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected