Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
class Solution { public: vector
> floodFill(vector
>& image, int sr, int sc, int color) { vector
> result = image; int n = image.size(); int m = image[0].size(); vector
> visited(n, vector
(m, false)); queue
q; q.push(sr); q.push(sc); visited[sr][sc] = true; int s_color = image[sr][sc]; result[sr][sc] = color; while(!q.empty()) { int ci = q.front(); q.pop(); int cj = q.front(); q.pop(); if(ci + 1 < n and !visited[ci + 1][cj] and image[ci + 1][cj] == s_color) { q.push(ci + 1); q.push(cj); visited[ci + 1][cj] = true; result[ci + 1][cj] = color; } if(ci - 1 >= 0 and !visited[ci - 1][cj] and image[ci - 1][cj] == s_color) { q.push(ci - 1); q.push(cj); visited[ci - 1][cj] = true; result[ci - 1][cj] = color; } if(cj + 1 < m and !visited[ci][cj + 1] and image[ci][cj + 1] == s_color) { q.push(ci); q.push(cj + 1); visited[ci][cj + 1] = true; result[ci][cj + 1] = color; } if(cj - 1 >= 0 and !visited[ci][cj - 1] and image[ci][cj - 1] == s_color) { q.push(ci); q.push(cj - 1); visited[ci][cj - 1] = true; result[ci][cj - 1] = color; } } return result; } };
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)