2022.11.22일 12문제 완료 기록.
문제를 풀면서 느낀점은 내가 알지 못하는 Math함수들의 종류이다. 간단히 소수점 없애기 Math.floor 정도만 인지하고있었지 다양하게 존재한다는걸 다시한번 느끼고 공부의 필요성을 느끼게되었다.
- 점의 위치 구하기
class Solution {
public int solution(int[] dot) {
int answer = 0;
if(dot[0]>0){
if(dot[1]>0){
answer=1;
}else{
answer=4;
}
}else{
if(dot[1]>0){
answer=2;
}else{
answer=3;
}
}
return answer;
}
}
- 삼각형의 완성조건 (1)
import java.util.*;
class Solution {
public int solution(int[] sides) {
int answer = 0;
Arrays.sort(sides);
if(sides[2] < sides[1]+sides[0]){
answer=1;
}else{
answer=2;
}
return answer;
}
}
- 배열 두배 만들기
class Solution {
public int[] solution(int[] numbers) {
int[] answer = new int [numbers.length];
for(int i=0;i<numbers.length;i++){
answer[i]=numbers[i]*2;
}
return answer;
}
}
- 특정 문자 제거하기
import java.util.*;
class Solution {
public String solution(String my_string, String letter) {
String answer = my_string.replace(letter,"");
return answer;
}
}
- 피자 나눠 먹기 (3)
class Solution {
public int solution(int slice, int n) {
int answer = 0;
if(n-slice > 0){
for(int i=0;i<n;i++){
if(n-slice*i>0){
answer++;
}
}
}else{
answer=1;
}
return answer;
}
}
- 문자 반복 출력하기
import java.util.*;
class Solution {
public String solution(String my_string, int n) {
String answer = "";
char[] arr = my_string.toCharArray();
for(int i=0;i<arr.length;i++){
for(int j=0;j<n;j++){
answer +=arr[i];
}
}
return answer;
}
}
- 최댓값 만들기 (1)
import java.util.*;
class Solution {
public int solution(int[] numbers) {
int answer = 0;
int[] max = numbers;
Arrays.sort(max); // 배열 자체를 정렬된 순서로 변경
answer = max[max.length - 1] * max[max.length - 2];
return answer;
}
}
- 편지
class Solution {
public int solution(String message) {
int answer = 0;
answer=message.length()*2;
return answer;
}
}
- 제곱수 판별하기
class Solution {
public int solution(int n) {
int answer = 0;
int i=0;
while(true){
if(i*i==n){
answer=1;
break;
}
if(i<1000){
i++;
}else{
answer=2;
break;
}
}
return answer;
}
}
'코딩테스트 & 알고리즘 및 기타 > 프로그래머스' 카테고리의 다른 글
프로그래머스 코딩테스트 입문 5 (0) | 2022.11.28 |
---|---|
프로그래머스 코딩테스트 입문 4 (0) | 2022.11.27 |
프로그래머스 코딩테스트 입문 3 (0) | 2022.11.27 |
프로그래머스 코딩테스트 입문1 (0) | 2022.11.22 |