Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active September 2, 2018 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/4b19f1a1a155963f063e7c95bb9aa9c2 to your computer and use it in GitHub Desktop.
Save thmain/4b19f1a1a155963f063e7c95bb9aa9c2 to your computer and use it in GitHub Desktop.
public class SlidingWindowMaximumNaive {
public void slidingWindow(int [] nums, int k){
for (int i = 0; i <nums.length - k ; i++) {
int max = nums[i];
for (int j = 1; j<=k ; j++) {
if(nums[i+j]>max)
max = nums[i+j];
}
System.out.print(max + " ");
}
}
public static void main(String[] args) {
int [] nums = {1, 2, 3, 2, 4, 1, 5, 6, 1};
int k = 3;
SlidingWindowMaximumNaive s = new SlidingWindowMaximumNaive();
s.slidingWindow(nums, k);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment