Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 93b32f5

Browse files
Update Tutorial.md
1 parent bd1f146 commit 93b32f5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎ArraysAndStrings/Tutorial.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,22 @@ public void maxSubArraySum (int arr[]) {
173173
}
174174
```
175175

176+
**given a 2D array of integers, sorted row wise and column wise. find if number exists in the array.**
177+
178+
Java supports multi-dimensional array by having array of arrays.
179+
180+
```
181+
public boolean findNum (int[][] arr, int num) {
182+
int row = 0;
183+
int column = arr[row].length-1;
184+
while(row >= 0 && column >=0 && row <= arr.length-1 && column <= arr.length-1) {
185+
if (arr[row][column] == num)
186+
return true;
187+
else if ( arr[row][column] < num)
188+
row++ ;
189+
else
190+
column--;
191+
}
192+
return false;
193+
}
194+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /