Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. vector<vector<int>> floodFill(vector<vector<int>>& image)
  2. {
  3. int n = image.size();
  4. int m = image[0].size();
  5.  
  6. vector<vector<int>> new_image(n, vector<int>(m, 0));
  7.  
  8. for (int i = 0; i < n; i++)
  9. {
  10. for (int j = 0; j < 0; j++)
  11. {
  12. if (isValid(i+1, j, n, m))
  13. {
  14. if (image[i+1][j] > image[i][j])
  15. new_image[i][j] = 0;
  16. }
  17. else if (isValid(i-1, j, n, m))
  18. {
  19. if (image[i - 1][j] > image[i][j])
  20. new_image[i][j] = 0;
  21. }
  22. else if (isValid(i, j+1, n, m))
  23. {
  24. if (image[i][j+1] > image[i][j])
  25. new_image[i][j] = 0;
  26. }
  27. else if (isValid(i, j-1, n, m))
  28. {
  29. if (image[i][j-1] > image[i][j])
  30. new_image[i][j] = 0;
  31. }
  32. if (isValid(i+1, j+1, n, m))
  33. {
  34. if (image[i+1][j+1] > image[i][j])
  35. new_image[i][j] = 0;
  36.  
  37. }
  38. else if (isValid(i+1, j-1, n, m))
  39. {
  40. if (image[i + 1][j-1] > image[i][j])
  41. new_image[i][j] = 0;
  42. }
  43. else if (isValid(i-1, j+1, n, m))
  44. {
  45. if (image[i - 1][j+1] > image[i][j])
  46. new_image[i][j] = 0;
  47. }
  48. else if (isValid(i-1, j-1, n, m))
  49. {
  50. if (image[i - 1][j-1] > image[i][j])
  51. new_image[i][j] = 0;
  52. }
  53. else
  54. new_image[i][j] = 1;
  55. }
  56. }
  57. return new_image;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement