Created
February 17, 2016 12:13
-
-
Save hanjae-jea/ad8b4a92f4c697f1788c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class test { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
Deque deque = new ArrayDeque<>(); | |
Map map = new HashMap(); | |
int n = in.nextInt(); | |
int m = in.nextInt(); | |
int uniqueIntegerArray = 0; | |
int answer = 0; | |
for (int i = 0; i < n; i++) { | |
int num = in.nextInt(); | |
deque.addLast(num); | |
try{ | |
int temp = (int)map.get(num); | |
map.remove(num); | |
map.put( num , temp + 1 ); | |
}catch(Exception e){ | |
uniqueIntegerArray ++; | |
map.put(num, 1); | |
} | |
// subsequence is full | |
if( i >= m ){ | |
int first = (int)deque.pollFirst(); | |
// map에 여러개 있으면 | |
int mapCount = (int)map.get(first); | |
if( mapCount > 1 ){ | |
map.put( first , mapCount - 1); | |
} | |
// map에 한 개 밖에 없었으면 | |
else{ | |
map.remove(first); | |
uniqueIntegerArray--; | |
} | |
} | |
if( answer < uniqueIntegerArray ) | |
answer = uniqueIntegerArray; | |
} | |
System.out.println(answer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment