Skip to content

Commit 0496a4b

Browse files
authored
Resolve the Young tableau search by step-wise.
The code start search the given value from the right-top to left-buttom.
1 parent d925e96 commit 0496a4b

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
@@ -1034,6 +1034,28 @@ f = lambda n: 1 if n < 2 else f(n - 1) + f(n - 2)
10341034

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

1037+
使用Step-wise线性搜索。
1038+
1039+
```python
1040+
def get_value(l, r, c):
1041+
return l[r][c]
1042+
1043+
def find(l, x):
1044+
m = len(l) - 1
1045+
n = len(l[0]) - 1
1046+
r = 0
1047+
c = n
1048+
while c >= 0 and r <= m:
1049+
value = get_value(l, r, c)
1050+
if value == x:
1051+
return True
1052+
elif value > x:
1053+
c = c - 1
1054+
elif value < x:
1055+
r = r + 1
1056+
return False
1057+
```
1058+
10371059
## 5 去除列表中的重复元素
10381060

10391061
用集合

0 commit comments

Comments
 (0)