Skip to content

Commit 0b6036b

Browse files
authored
Merge pull request taizilongxu#19 from ph87/master
解决杨氏矩阵搜索题
2 parents 3f3b71c + 0496a4b commit 0b6036b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,28 @@ f = lambda n: 1 if n < 2 else f(n - 1) + f(n - 2)
10631063

10641064
在一个m行n列二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
10651065

1066+
使用Step-wise线性搜索。
1067+
1068+
```python
1069+
def get_value(l, r, c):
1070+
return l[r][c]
1071+
1072+
def find(l, x):
1073+
m = len(l) - 1
1074+
n = len(l[0]) - 1
1075+
r = 0
1076+
c = n
1077+
while c >= 0 and r <= m:
1078+
value = get_value(l, r, c)
1079+
if value == x:
1080+
return True
1081+
elif value > x:
1082+
c = c - 1
1083+
elif value < x:
1084+
r = r + 1
1085+
return False
1086+
```
1087+
10661088
## 5 去除列表中的重复元素
10671089

10681090
用集合

0 commit comments

Comments
 (0)