@@ -211,9 +211,38 @@ function greatestProduct(nums){
211
211
var currentValue = 0 ;
212
212
for ( var i = 0 ; i < nums . length ; i ++ ) {
213
213
for ( var j = 0 ; j < nums [ i ] . length ; j ++ ) {
214
+ if ( i === 0 && j === 0 ) {
215
+ currentValue = nums [ 0 ] [ 1 ] * nums [ 1 ] [ 0 ] ;
216
+ if ( finalValue < currentValue ) {
217
+ finalValue = currentValue ;
218
+ }
219
+ }
220
+ else if ( i === 0 && j === nums [ 0 ] . length - 1 ) {
221
+ currentValue = nums [ i ] [ j - 1 ] * nums [ i + 1 ] [ j ] ;
214
222
215
-
216
- if ( i > 0 && i < nums . length - 1 && j > 0 && j < nums [ i ] . length - 1 ) {
223
+ if ( finalValue < currentValue ) {
224
+ finalValue = currentValue ;
225
+ }
226
+ }
227
+ else if ( i === nums . length - 1 && j === nums [ i ] . length - 1 ) {
228
+ currentValue = nums [ i - 1 ] [ j ] * nums [ i ] [ j - 1 ]
229
+ if ( finalValue < currentValue ) {
230
+ finalValue = currentValue ;
231
+ }
232
+ }
233
+ else if ( i === nums . length - 1 && j === 0 ) {
234
+ currentValue = nums [ i - 1 ] [ j ] * nums [ i ] [ j + 1 ] ;
235
+ if ( finalValue < currentValue ) {
236
+ finalValue = currentValue ;
237
+ }
238
+ }
239
+ else if ( i === 0 ) {
240
+ currentValue = nums [ i ] [ j - 1 ] * nums [ i ] [ j + 1 ] * nums [ i + 1 ] [ j ] ;
241
+ if ( finalValue < currentValue ) {
242
+ finalValue = currentValue ;
243
+ }
244
+ }
245
+ else if ( i > 0 && i < nums . length - 1 && j > 0 && j < nums [ i ] . length - 1 ) {
217
246
218
247
currentValue = nums [ i - 1 ] [ j ] * nums [ i ] [ j + 1 ] * nums [ i ] [ j - 1 ] * nums [ i + 1 ] [ j ] ;
219
248
0 commit comments