Guest User

Untitled

a guest
Nov 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. // IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM
  2. import java.util.*;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. // SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED
  6. // DEFINE ANY CLASS AND METHOD NEEDED
  7. // CLASS BEGINS, THIS CLASS IS REQUIRED
  8. public class Solution
  9. {
  10. // METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIRED
  11. public List<Integer> cellCompete(int[] states, int days)
  12. {
  13. for(int j=0; j<days; j++){
  14. int[] nextDay = new int[states.length];
  15. for(int i=0; i<states.length; i++){
  16.  
  17. int next;
  18. int previous;
  19.  
  20. if(i==0){
  21. previous = 0;
  22. }
  23. else{
  24. previous = states[i-1];
  25. }
  26.  
  27. if(i==states.length-1){
  28. next = 0;
  29. }
  30. else{
  31. next = states[i+1];
  32. }
  33.  
  34. if(previous==next){
  35. nextDay[i] = 0;
  36. }
  37. else{
  38. nextDay[i] = 1;
  39. }
  40. }
  41. states = nextDay;
  42. }
  43.  
  44. return this.toList(states);
  45. }
  46.  
  47. public List<Integer> toList(int[] ints)
  48. {
  49. List<Integer> intList = new ArrayList<Integer>();
  50. for (int index = 0; index < ints.length; index++)
  51. {
  52. intList.add(ints[index]);
  53. }
  54. return intList;
  55. }
  56. // METHOD SIGNATURE ENDS
  57. }
Add Comment
Please, Sign In to add comment