Skip to content

Commit f6e1098

Browse files
committed
增加求数组最大深度
1 parent 0dedd48 commit f6e1098

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

typescript/src/nowcoder/examTop101.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,29 @@ function BM23() {
101101
const result = preorderTraversal(root)
102102
console.log(result) // 输出 [1, 2, 4, 5, 3]
103103
}
104-
BM23()
104+
// BM23()
105+
106+
function match() {
107+
const str = 'aeiou wolppzxc alwmdf String prototype'
108+
const result = str.match(/a|e|i|o|u/g)
109+
console.log(result, result.length)
110+
}
111+
// match()
112+
113+
function getMaxDepth() {
114+
const arr = [1, 1, [2, 2], [2, [3, 3, [4, 4], [4, [5, 5]]]]]
115+
const depth = []
116+
const getDepth = (arr, deep) => {
117+
arr.forEach((a) => {
118+
if (Array.isArray(a)) {
119+
getDepth(a, deep + 1)
120+
} else {
121+
depth.push(deep)
122+
}
123+
})
124+
}
125+
126+
getDepth(arr, 1)
127+
console.log(Math.max(...depth))
128+
}
129+
getMaxDepth()

0 commit comments

Comments
 (0)