Java for Leetcode 036 Valid Sudoku

Source: Internet
Author: User

Determine if a Sudoku is valid, according To:sudoku puzzles-the Rules.

The Sudoku board could be partially filled, where empty cells is filled with the character ‘.‘ .

Problem Solving Ideas:

The legendary Sudoku (nine Gongge) question, honestly traverse three rules:

Java implementations:

Static public Boolean Isvalidsudoku (char[][] board) {for (int i = 0; i < board.length; i++) {hashmap<character, Inte  ger> HashMap = new Hashmap<character, integer> (); for (int j = 0; J < Board[0].length; J + +) {if (board[i][j]! = ‘.‘) {if (Hashmap.containskey (Board[i][j])) return False;hashmap.put (Board[i][j], 1);}}} for (int j = 0; J < Board[0].length; J + +) {hashmap<character, integer> HashMap = new Hashmap<character, intege R> (); for (int i = 0; i < board.length; i++) {if (board[i][j]! = '. ')    {if (Hashmap.containskey (Board[i][j])) return False;hashmap.put (Board[i][j], 1);}}} for (int i = 0; i < board.length; i + = 3) {for (int j = 0; J < board[0].length; J + = 3) {hashmap<  Character, integer> hashmap = new Hashmap<character, integer> (); for (int k = 0; k < 9; k++) {if (board[i + k/ 3][j + k% 3]! = '. ') {if (Hashmap.containskey (board[i + k/3][j + k% 3])) return False;hashmap.put (board[i + k/3][j + k% 3], 1);}}} RetUrn true;} 

Java for Leetcode 036 Valid Sudoku

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.