当前位置: 首页 > news >正文

[算法很美打卡] 多维数组篇 (打卡第一天)

文章目录

  • 顺时针打印二维数组
  • 0所在的行列清零

顺时针打印二维数组

在这里插入图片描述

package 每日算法学习打卡.算法打卡.七月份.七月二十六号;public class test1 {public static void main(String[] args) {int[][] matrix = {{1,2},{5,6},{9,10},{13,14},};print(matrix);}static void print(int[][] matrix){int leftUpRow =0,leftUpCol =0,rightDownRow = matrix.length-1,rightDownCol = matrix[0].length-1;while(leftUpRow<=rightDownRow && leftUpCol <= rightDownCol){int r = leftUpRow,c = leftUpCol;while(c<=rightDownCol){System.out.print(matrix[r][c++]+" ");}r++;c = rightDownCol;while(r<=rightDownRow){System.out.print(matrix[r++][c]+" ");}c--;r= rightDownRow;while(c>=leftUpCol){System.out.print(matrix[r][c--]+" ");}r--;c = leftUpCol;while(r>leftUpRow){System.out.print(matrix[r--][c]+" ");}leftUpCol++;leftUpRow++;rightDownCol--;rightDownRow--;}}
}

0所在的行列清零

在这里插入图片描述

package 每日算法学习打卡.算法打卡.七月份.七月二十六号;public class test2 {public static void main(String[] args) {int[][] matrix = {{1,2,3,4,100},{5,6,7,0,101},{9,0,11,12,102},{13,14,15,16,103},{104,105,106,106,108},};solve(matrix);for(int i =0;i<matrix.length;i++){for(int j =0;j<matrix[0].length;j++){System.out.print(matrix[i][j]+" ");}System.out.println();}}static void solve(int[][] matrix){//使用辅助数组来进行测试int M = matrix.length;int N = matrix.length;//记录哪些行出现了0int[] rowRecord = new int[M];int[] colRecord = new int[N];for(int i =0;i<M;i++){for(int j =0;j<N;j++){if(matrix[i][j] == 0){rowRecord[i] =1;colRecord[j] =1;}}}for(int row = 0;row < N;row++){for(int col = 0;col<M;col++){if(rowRecord[row] ==1 || colRecord[col] == 1){matrix[row][col] =0;}}}}}
http://www.lryc.cn/news/95993.html

相关文章:

  • 微服务系列(1)-who i am?
  • 记录这这段时间发生的事情。
  • 发布npm包流程
  • 面试官:Redis 为什么变慢了?怎么解决?
  • Docker:开启应用程序开发新篇章的利器
  • Python面向对象(三)(继承、封装)
  • Redis Stream 流的深度解析与实现高级消息队列【一万字】
  • 一个灵活、现代的Android应用架构
  • redis高级篇 springboot+redis+bloomfilter实现过滤案例
  • mybatis学习笔记之在WEB中应用MyBatis
  • 宿主可以访问公网 Docker容器里无法访问 Temporary failure in name resolution
  • CentOS7系统MBR、GRUB2、内核启动流程报错问题
  • 剑指YOLOv5改进最新MPDIoU损失函数(23年7月首发论文):超越现有多种G/D/C/EIoU,高效准确的边界框回归的损失,高效涨点
  • CAN bus off ——ISO11898
  • 如何评测一个大语言模型?
  • React中useMemo和useCallback的区别
  • SpringBoot 快速实现IP地址解析
  • 亚马逊、速卖通,阿里国际等平台测评如何用自养号测评补单
  • ubuntu挂载ext4文件系统
  • MySQL 读写分离
  • 【多线程例题】顺序打印abc线程
  • WebSocket工具类
  • Linux 的 crontab
  • 十二.Redis模拟集群搭建
  • IDEA导入微服务项目后自动将微服务展示在service面板中
  • MySQL体系结构及执行过程
  • 21. MySQL基础知识
  • 【ArcGIS Pro微课1000例】0029:绘制全球海洋波纹荡漾效果图
  • 2023“钉耙编程”中国大学生算法设计超级联赛(3)8-bit Zoom
  • 【PWN · ret2text | 伪rand()】[HDCTF 2023]pwnner