Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Here's some of the inputs
- int[] list1 = {1, 6, 2, 1, 4, 1, 2, 1, 8};
- int[] list2 = {1, 2, 1};
- System.out.println(contains(list1, list2)); // true
- System.out.println(contains(list2, list1)); // false
- System.out.println(contains(new int[]{1, 2, 1, 2, 3}, new int[]{1, 2, 3})); //true
- System.out.println(contains(new int[]{8, 8, 8, 8, 4, 8, 8, 8, 8, 2, 8}, new int[]{8, 8, 8, 8, 4})); // this one is returning true but it shouldn't!
- */
- //something wrong with this code I have no clue what though and it's driving me nuts!!!!!!!
- public static boolean contains(int arr1[], int arr2[])
- {
- int arr2slot = 0;
- //boolean
- for(int i = 0; i < arr1.length; i++)
- {
- if(arr1[i] != arr2[arr2slot])
- {
- arr2slot = 0;
- }
- if(arr1[i] == arr2[arr2slot] )
- {
- if(arr2slot < arr2.length - 1)
- {
- arr2slot++;
- }
- }
- if(arr2slot == arr2.length - 1 && arr1[i] == arr2[arr2slot])
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement