File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean check (int []data ,int start ,int size ){
3+ for (int i =start +1 ;i <start +size +1 ;i ++) {
4+ if (i >=data .length || data [i ] >> 6 != 0b10){
5+ return false ;
6+ }
7+ }
8+ return true ;
9+ }
10+ public boolean validUtf8 (int [] data ) {
11+ int start =0 ;
12+ while (start <data .length ){
13+ int first =data [start ];
14+ //111100으로 시작하면 나머지가 3비트여야한다.
15+ if (first >>3 ==0b11110&&check (data ,start ,3 )){
16+ start +=4 ;
17+ //1110xxxx 패턴으로 시작하는지 확인/ 나머지가 2비트여야함
18+ }else if (first >>4 ==0b1110&&check (data ,start ,2 )){
19+ start +=3 ;
20+ //110xxxx 패턴으로 시작하는지 확인/ 나머지가 1비트여야함
21+ }else if (first >>5 ==0b110&&check (data ,start ,1 )){
22+ start +=2 ;
23+ //0xxxxxxx 패턴으로 시작하는지 확인/ 1바이트 문자
24+ }else if (first >>7 ==0 ){
25+ start ++;
26+ }else {
27+ return false ;
28+ }
29+ }
30+ return true ;
31+
32+
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int [] maxSlidingWindow (int [] nums , int k ) {
3+
4+ List <Integer >result =new ArrayList <>();
5+
6+ Queue <Integer > window =new LinkedList <>();
7+
8+ int currentMax =Integer .MIN_VALUE ;
9+
10+ for (int i =0 ;i <nums .length ;i ++){
11+ window .add (nums [i ]);
12+
13+ if (i <k -1 ) continue ;
14+
15+ if (currentMax ==Integer .MIN_VALUE ){
16+ currentMax =window .stream ().max (Integer ::compareTo ).get ();
17+ }else if (currentMax <nums [i ]){
18+ currentMax =nums [i ];
19+ }
20+ result .add (currentMax );
21+ if (currentMax ==window .poll ())currentMax =Integer .MIN_VALUE ;
22+ }
23+ return result .stream ().mapToInt (Integer ::intValue ).toArray ();
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public boolean contains (String str ,String t ){
3+ StringBuilder sb =new StringBuilder (str );
4+
5+ for (char elem :t .toCharArray ()){
6+ if (sb .indexOf (String .valueOf (elem ))!=-1 )
7+ sb .deleteCharAt (sb .indexOf (String .valueOf (elem )));
8+ else return false ;
9+ }
10+ return true ;
11+ }
12+ public String minWindow (String s , String t ) {
13+ for (int windowSize =t .length ();windowSize <s .length ()+1 ;windowSize ++){
14+ for (int left =0 ;left <s .length ()-windowSize +1 ;left ++){
15+ String str =s .substring (left ,left +windowSize );
16+
17+ if (contains (str ,t ))return str ;
18+ }
19+ }
20+ return "" ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments