Submission Detail

133 / 133 test cases passed.
Status:

Accepted

Runtime: 0 ms
Memory Usage: 41.2 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
80
85
90
95
100
105
110
java
Runtime (ms)
Distribution (%)

0
1
2
3
4
5
6
7
8
9
10
80
90
100
110
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

41250
40000
40250
40500
40750
41000
41500
41750
42000
42250
42500
2
4
6
8
10
12
java
You are here!
Your memory usage beats 69.17 % of java submissions.
Memory (KB)
Distribution (%)

41250
40000
40250
40500
40750
41000
41500
41750
42000
42250
42500
5
10
Zoom area by dragging across this chart

Invite friends to challenge Search a 2D Matrix


Submitted Code: 0 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int start_row = 0;
for (int i = 0; i < matrix.length; i++)
if (target < matrix[i][0])
continue;
else {
start_row = i;
break;
}
boolean found = false;
for (int i = start_row; i < matrix.length; i++)
if (binarySearch(matrix[i],target,found) == true)
return true;
return false;
}
boolean binarySearch(int[] arr, int target, boolean found) {
int mp = arr.length/2;
if (found == true)
return found;
if (arr.length == 0)
return false;
if (arr[mp] == target)
return true;
int[] left = new int[mp];
int[] right = new int[arr.length-mp-1];
for (int i = 0; i < mp; i++)
left[i] = arr[i];
for (int i = 0; i < arr.length-mp-1; i++)
right[i] = arr[mp+i+1];
if (target < arr[mp])
found = binarySearch(left,target,found);
if (target > arr[mp])
found = binarySearch(right,target,found);
return found;
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX