Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const V = [
- [1 , 3 , 8 , 31, 34],
- [12, 3 , 8 , 9 , 11],
- [4 , 7 , 2 , 12, 34],
- [8 , 13, 8 , 21, 4 ],
- [8 , 2 , 82, 11, 7 ],
- ];
- // T(N) = 4 + 4SQRT(N) + N
- N * N
- const PeakFinding2D = function(matrix) {
- // K
- // V[0][0]
- // V[0][matrix.length - 1]
- // V[matrix.length - 1][0]
- // V[matrix.length - 1][matrix.length - 1]
- // SQRT(N)
- for(let i = 1; i < matrix.length - 1; i++) {
- if(V[i][0] > V[i - 1][0] && V[i][0] > V[i + 1][0] && V[i][0] > V[i][1]) {
- return V[i][0];
- }
- }
- // SQRT(N)
- for(let i = 0; i < matrix.length; i++) {
- console.log(V[i][matrix.length - 1])
- }
- // SQRT(N)
- for(let i = 0; i < matrix.length; i++) {
- console.log(V[0][i])
- }
- // SQRT(N)
- for(let i = 0; i < matrix.length; i++) {
- console.log(V[matrix.length - 1][i])
- }
- // SQRT(N)*SQRT(N) = N
- // SQRT(N)
- for(let i = 1; i < matrix.length - 1; i++) {
- // SQRT(N)
- for(let j = 1; j < matrix[i].length - 1; j++) {
- if(true
- && V[i][j] > V[i][j + 1]
- && V[i][j] > V[i][j - 1]
- && V[i][j] > V[i + 1][j]
- && V[i][j] > V[i - 1][j]
- ) {
- return V[i][j];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement