Deep_Lee
article thumbnail
์„น์…˜4. HashMap, TreeSet ( ํ•ด์‰ฌ, ์ •๋ ฌ์ง€์› Set )

ํ•™๊ธ‰ ํšŒ์žฅ ์•„๋‚˜๊ทธ๋žจ(HashMap) ๋งค์ถœ์•ก์˜ ์ข…๋ฅ˜(Hash, sliding window) ๋ชจ๋“  ์•„๋‚˜๊ทธ๋žจ ์ฐพ๊ธฐ ( Hash, sliding window : ์‹œ๊ฐ„๋ณต์žก๋„ O(n)) K๋ฒˆ์งธ ํฐ ์ˆ˜ 1. ํ•™๊ธ‰ํšŒ์žฅ import java.util.*; public class Main { public char solution(int n,String str){ char answer=' '; HashMap map=new HashMap(); for(char x:str.toCharArray()){ map.put(x,map.getOrDefault(x,0)+1); } int max=Integer.MIN_VALUE; for(char key:map.keySet()){ if(map.get(key)>max){ max=map.get(ke..

article thumbnail
์„น์…˜ 3. Two points, Sliding window[ํšจ์œจ์„ฑ : O(n^2)-->O(n)]

1. ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ ( two pointers algorithm ) 2. ๊ณตํ†ต์›์†Œ๊ตฌํ•˜๊ธฐ( two points algorithm ) 3. ์ตœ๋Œ€ ๋งค์ถœ( Sliding window ) 4. ์—ฐ์†๋ถ€๋ถ„์ˆ˜์—ด ( ๋ณตํ•ฉ์  ๋ฌธ์ œ ) 5.1 ์—ฐ์†๋œ ์ž์—ฐ์ˆ˜์˜ ํ•ฉ ( two pointers ) 5.2 ์—ฐ์†๋œ ์ž์—ฐ์ˆ˜์˜ ํ•ฉ ( ์ˆ˜ํ•™ ) 6. ์ตœ๋Œ€ ๊ธธ์ด ์—ฐ์†๋ถ€๋ถ„์ˆ˜์—ด ( ๋ณตํ•ฉ์  ๋ฌธ์ œ ) 1. ๋‘ ๋ฐฐ์—ด ํ•ฉ์น˜๊ธฐ ( two pointers algorithm ) import java.util.*; public class Main { public ArrayList solution(int n, int m, int[] a, int[] b){ ArrayList answer=new ArrayList(); int p1=0, p2=0; while(p1

article thumbnail
์„น์…˜1. String(๋ฌธ์ž์—ด)

1. ๋ฌธ์ž์ฐพ๊ธฐ import java.util.Scanner; public class Main { public int solution(String str, char t){ int answer=0; str=str.toUpperCase(); t=Character.toUpperCase(t); for(int i=0; im){ // ์ตœ๋Œ“๊ฐ’ ์•Œ๊ณ ๋ฆฌ์ฆ˜ m=len; answer=x; } } return answer; } public static void main(String[] args){ Main T = new Main(); Scanner kb = new Scanner(System.in); String str = kb.nextLine(); System.out.print(T.solution(str); } } 4. ๋‹จ์–ด ..

article thumbnail
์„น์…˜2. Array( 1,2์ฐจ์› ๋ฐฐ์—ด )

2.1 ํฐ ์ˆ˜ ์ถœ๋ ฅํ•˜๊ธฐ solution import java.util.*; class Main { public ArrayList solution(int n, int[] arr){ ArrayList answer = new ArrayList(); answer.add(arr[0]); for(int i=1; iarr[i-1]) answer.add(arr[i]); } return answer; } public static void main(String[] args) { Main T = new Main(); Scanner kb = new Scanner(System.in); int n = kb.nextInt(); int[] arr = new int[n]; for(int i=0; i