G-Face by Prepare:straight Partition of A Deck of Cards

Source: Internet
Author: User

If1, 2, 3, 4, 4, 5, 5, 6, 7, 8--True

This is with a hashtable,key is a number, value is the number of occurrences

Then traverse the original array, each number will be the hash from the beginning of their own 5 color number is 1, if the missing number indicates that cannot be divided

It's easy to be wrong!

Wrong many times, is the color of the next 5, if there is no color or the number of color is 0, error

1  Packagestraight;2 ImportJava.util.*;3 4  Public classSolution {5      Public BooleanDetermine (int[] arr) {6Hashmap<integer, integer> map =NewHashmap<integer, integer>();7          for(intElem:arr) {8             if(Map.containskey (elem)) {9Map.put (Elem, Map.get (elem) +1);Ten             } One             ElseMap.put (Elem, 1); A          } -          -          for(inti=0; i<arr.length; i++) { the             if(Map.get (arr[i]) = = 0)Continue; -              for(intJ=arr[i]; j<arr[i]+5; J + +) { -                 if(!map.containskey (j))return false; -                 if(Map.get (j) = = 0)return false; +                 Else { -Map.put (J, Map.get (j)-1); +                 } A             } at             if(Map.get (arr[i]) > 0) i--; -         } -         return true; -     } -      -  in     /** -      * @paramargs to      */ +      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub theSolution Sol =Newsolution (); *         Booleanres = Sol.determine (New int[]{1,2,3,4,4,5,5,5,6,6,7,7,8,8,9}); $         if(RES) System.out.println ("true");Panax Notoginseng         ElseSystem.out.println ("false"); -     } the  +}

G-Face by Prepare:straight Partition of A Deck of Cards

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.