回答編集履歴
3
入れ子が深くなりすぎるのを嫌って修正
test
CHANGED
@@ -70,19 +70,17 @@
|
|
70
70
|
|
71
71
|
int lastNum = Integer.MIN_VALUE;
|
72
72
|
|
73
|
-
for (int i = 0; i < t.length; t++)
|
73
|
+
for (int i = 0; i < t.length; t++)
|
74
74
|
|
75
|
-
if (t[i].length
|
75
|
+
if (t[i].length <= j) continue;
|
76
76
|
|
77
|
-
|
77
|
+
if (t[i][j] < lastNum) {
|
78
78
|
|
79
|
-
|
79
|
+
return false;
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
lastNum = t[i][j];
|
84
80
|
|
85
81
|
}
|
82
|
+
|
83
|
+
lastNum = t[i][j];
|
86
84
|
|
87
85
|
}
|
88
86
|
|
2
インデントがおかしかったので修正
test
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
for (int j = 0; j < max; j++) {
|
70
70
|
|
71
|
-
int lastNum = Integer.MIN_VALUE;
|
71
|
+
int lastNum = Integer.MIN_VALUE;
|
72
72
|
|
73
73
|
for (int i = 0; i < t.length; t++) {
|
74
74
|
|
1
コード修正と、補足説明
test
CHANGED
@@ -36,6 +36,24 @@
|
|
36
36
|
|
37
37
|
例えばj=1で考えますが、t[i][1]を、iを動かしながら増加しているか調べます。ただし、この時t[i]に1番の要素があるか、つまりt[i].lengthが2以上あるかを確かめる必要があります(しないと例外発生)。
|
38
38
|
|
39
|
+
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
↓j=1ならこの縦方向を見る(各配列の1番目の要素)
|
44
|
+
|
45
|
+
t[0]:{1,4,5,10,11} <-t[0][1]は4
|
46
|
+
|
47
|
+
t[1]:{2,6,8} <-t[1][1]は6>4で成立
|
48
|
+
|
49
|
+
t[2]:{3,9,12} <-t[2][1]は9>6で成立
|
50
|
+
|
51
|
+
t[3]:{7} <-t[3][1]はないため、この回避をしないと例外発生
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
|
39
57
|
```java
|
40
58
|
|
41
59
|
public static boolean columnValuesIncrease(int [][] t){
|
@@ -54,13 +72,17 @@
|
|
54
72
|
|
55
73
|
for (int i = 0; i < t.length; t++) {
|
56
74
|
|
57
|
-
if (t[i].length > j
|
75
|
+
if (t[i].length > j) {
|
58
76
|
|
77
|
+
if (t[i][j] < lastNum) {
|
78
|
+
|
59
|
-
return false;
|
79
|
+
return false;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
lastNum = t[i][j];
|
60
84
|
|
61
85
|
}
|
62
|
-
|
63
|
-
lastNum = t[i][j];
|
64
86
|
|
65
87
|
}
|
66
88
|
|