Movatterモバイル変換


[0]ホーム

URL:


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

Commitd27968b

Browse files
Ishani08poyea
authored andcommitted
Create Searching in sorted matrix (TheAlgorithms#738)
* Create Searching in sorted matrix* Rename Searching in sorted matrix to searching_in_sorted_matrix.py
1 parent96c36f8 commitd27968b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎matrix/searching_in_sorted_matrix.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
defsearch_in_a_sorted_matrix(mat,m,n,key):
2+
i,j=m-1,0
3+
whilei>=0andj<n:
4+
ifkey==mat[i][j]:
5+
print('Key %s found at row- %s column- %s'% (key,i+1,j+1))
6+
return
7+
ifkey<mat[i][j]:
8+
i-=1
9+
else:
10+
j+=1
11+
print('Key %s not found'% (key))
12+
13+
14+
defmain():
15+
mat= [
16+
[2,5,7],
17+
[4,8,13],
18+
[9,11,15],
19+
[12,17,20]
20+
]
21+
x=int(input("Enter the element to be searched:"))
22+
print(mat)
23+
search_in_a_sorted_matrix(mat,len(mat),len(mat[0]),x)
24+
25+
26+
if__name__=='__main__':
27+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp