亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刷java算法題出現了空指針錯誤

刷java算法題出現了空指針錯誤

長風秋雁 2019-03-01 10:40:20
public class Solution { public void setZeroes(int[][] matrix) { int m = matrix.length; int n = matrix[0].length; Boolean[] rows = new Boolean[m]; Boolean[] cols = new Boolean[n]; for(int i = 0; i< m; i++){ for(int j = 0; j< n; j++){ if(matrix[i][j] == 0){ rows[i] = true; cols[j] = true; } } } for(int i = 0; i<m; i++){ for(int j = 0; j< n; j++){ if(rows[i] ==true || cols[j] == true) matrix[i][j] = 0; } } } } 該題是leetcode第73題Set Matrix Zeroes,題目如下: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.我的做法是,加一個行數組、一個列數組,來記錄哪些行、哪些列有0,但是提交時出現了空指針錯誤。
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 400 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號