What is the O(n) of this leetcode solution? I was wondering what the O(n) for this leetcode solution would be. To clarify, this code is supposed to validate a sudoku puzzle. The portion of my code that would run the longest would be the last block. Since there are 4 for loops in this code block, would it take O(n^4) time? What about space complexity?

class Solution {
public boolean isValidSudoku(char[][] board) {
HashMap<Character, Integer> sudoku = new HashMap<Character, Integer>();
final int size = 9;

for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
char num = board[i][j];

if(num != '.') {
if(!sudoku.containsKey(num)) {
sudoku.put(num, 1);
}
else {
return false;
}
}
}
sudoku.clear();
}

for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
char num = board[j][i];

if(num != '.') {
if(!sudoku.containsKey(num)) {
sudoku.put(num, 1);
}
else {
return false;
}
}
}
sudoku.clear();
}

for(int i = 0; i <= 6; i+=3) {
for(int j = 0; j <= 6; j+=3) {
for(int r = 0; r < 3; r++) {
for(int c = 0; c < 3; c++) {
char num = board[r+i][c+j];

if(num != '.') {
if(!sudoku.containsKey(num)) {
sudoku.put(num, 1);
}
else {
return false;
}
}
}
}
sudoku.clear();
}
}

return true;
}
} Sullivan’s Hosting Expands into VPS Services with Phenomenal Deals! Starting at \$1/month! 