csharp进阶练习题:当只有零点的带外的行和列【难度:2级】--景越C#经典编程题库,不同难度C#练习题,适合自学C#的新手进阶训练

mac2026-03-19  3

csharp进阶练习题:当只有零点的带外的行和列【难度:2级】:

地带外排,当零的列

对于一个矩阵

0 0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 4 5 6 7 0 0 0 0 0 0 0 0 0 0 0

你必须裁剪只能由零的所有外部行和列.对于前面的示例:

1 2 3 0 0 0 0 0 4 5 6 7

你的任务是准备一个功能crop返回最终矩阵.

编程目标:

public class Kata { public static int[][] Crop(int[][] matrix) { return matrix; } }

测试样例:

namespace Solution { using NUnit.Framework; using System; using System.Linq; [TestFixture] public class KataTests public void BasicTests() { var matrix = new int[][] { new int[] { 0,0,0,0,0,0,0,0 }, new int[] { 0,1,2,3,0,0,0,0 }, new int[] { 0,0,0,0,0,0,0,0 },

最佳答案(多种解法):

点击查看答案

更多关联题目:

免责申明

本博客所有编程题目及答案均收集自互联网,主要用于供网友学习参考,如有侵犯你的权益请联系管理员及时删除,谢谢 题目收集至https://www.codewars.com/ https://www.codewars.com/kata/strip-external-rows-and-columns-when-only-zeros

最新回复(0)