01-23 07:25
Recent Posts
Recent Comments
Tags
- μλ°
- Java
- νμ΄μ¬
- appetizer
- νμ΄μ곡λͺ¨μ
- RaspberryPi
- python
- μ΄λΈμ
- TSQL
- ICTλ©ν λ§
- API MarketPlace κΈλ‘λ² μν¬ν°μ¦
- μ¨μΌλν
- μ‘νκ³
- μ€ν½μ€λΉ
- JOBνκ³
- mysql
- Naver Cloud
- λ°μ΄ν°λ² μ΄μ€
- μ€ν½λ ν
- APIλ§μΌνλ μ΄μ€
- DATABASE
- ICT
- νλ‘λ³΄λ Έ
- DB
- μλμ΄λ Έ
- Spring
- SQL
- linux
- ict곡λͺ¨μ
- νμ΄μ
- Today
- Total
miinsun
[Algorithm]μκ³ λ¦¬μ¦ μλ°_47 μ€λ³΅ νμΈ λ³Έλ¬Έ
π¬ λ¬Έμ μ€λͺ
νμλ€ λ°μλ Nλͺ μ νμλ€μ΄ μμ΅λλ€. μ μλμ λ° νμλ€μκ² 1λΆν° 10,000,000κΉμ§μ μμ°μ μ€μμ κ°μκ° μ’μνλ μ«μ νλ μ μ΄ λ΄λΌκ³ νμ΅λλ€.
λ§μ½ Nλͺ μ νμλ€μ΄ μ μ΄λΈ μ«μ μ€ μ€λ³΅λ μ«μκ° μ‘΄μ¬νλ©΄ D(duplication)λ₯Ό μΆλ ₯νκ³ , Nλͺ μ΄ λͺ¨λ κ°μ λ€λ₯Έ μ«μλ₯Ό μ μ΄λλ€λ©΄ U(unique)λ₯Ό μΆλ ₯νλ νλ‘κ·Έλ¨μ μμ±νμΈμ.
π¨ μ μΆλ ₯ μ
μ λ ₯ - 첫 λ²μ§Έ μ€μ μμ°μ N(5<=N<=100,000)μ΄ μ£Όμ΄μ§λ€.
λ λ²μ§Έ μ€μ νμλ€μ΄ μ μ΄ λΈ Nκ°μ μμ°μκ° μ λ ₯λλ€.
8
20 25 52 30 39 33 43 33
μΆλ ₯ - 첫 λ²μ§Έ μ€μ D λλ Uλ₯Ό μΆλ ₯νλ€.
D
β
π» Solution.java
import java.util.*;
public class Main {
public String solution(int n, int [] arr) {
String answer = "U";
for(int i = 0; i < arr.length; i++) {
int search = arr[i];
for(int j = 0; j < arr.length; j++) {
if(i == j)
continue;
else {
if(search == arr[j]) {
return "D";
}
}
}
}
return answer;
}
public static void main(String[] args){
Main main = new Main();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
System.out.print(main.solution(n, arr));
sc.close();
return ;
}
}
μ λ ¬ Version
import java.util.*;
public class Main {
public String solution(int n, int [] arr) {
String answer = "U";
Arrays.sort(arr);
for(int i = 0; i < n -1; i++){
if(arr[i] == arr[i+1]) return "D";
}
return answer;
}
public static void main(String[] args){
Main main = new Main();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
System.out.print(main.solution(n, arr));
sc.close();
return ;
}
}
'Algorithm > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Algorithm]μκ³ λ¦¬μ¦ μλ°_49 μ’ν μ λ ¬ (0) | 2022.01.12 |
---|---|
[Algorithm]μκ³ λ¦¬μ¦ μλ°_48 μ₯λκΎΈλ¬κΈ° (0) | 2022.01.12 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_46 LRU(μΊμ, μΉ΄μΉ΄μ€ λ³ν) (0) | 2022.01.12 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_45 μ½μ μ λ ¬ (0) | 2022.01.10 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_44 λ²λΈ μ λ ¬ (0) | 2022.01.10 |
Comments