Skip to content

Commit e780019

Browse files
authored
Create find_elements_in_matrix.py
1 parent 8ad0ece commit e780019

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

find_elements_in_matrix.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
"""
5+
@param Matrix: the input
6+
@return: the element which appears every row
7+
"""
8+
def FindElements(self, Matrix):
9+
# write your code here
10+
di = {}
11+
for row in Matrix:
12+
rc = {}
13+
for i in row:
14+
rc[i] = 1
15+
for k in rc.keys():
16+
if k in di:
17+
di[k] += 1
18+
else:
19+
di[k] = 1
20+
for k, v in di.items():
21+
if v == len(Matrix):
22+
return k
23+
24+
# easy: http://lintcode.com/zh-cn/problem/find-elements-in-matrix/

0 commit comments

Comments
 (0)