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)); int di[] = {0, 0, -1, 1}; int dj[] = {-1, 1, 0, 0}; 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(); for(int i = 0; i < 4; i++) { int ti = ci + di[i]; int tj = cj + dj[i]; if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and image[ti][tj] == s_color) { q.push(ti); q.push(tj); visited[ti][tj] = true; result[ti][tj] = 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)