티스토리 뷰
[문제]
[풀이]
- 이건 내가 직접 풀었다. 내 풀이는 아래와 같다.
class Solution {
public int solution(int[] common) {
int answer = 0;
int one = common[0];
int two = common[1];
int thr = common[2];
if((two - one) == (thr - two)) {
answer = common[common.length - 1] + (two - one);
} else {
answer = common[common.length - 1] * (two / one);
}
return answer;
}
}
- 쉬운 문제라 다른 사람의 풀이도 다 비슷비슷했다.
- 아래의 풀이는 변수 선언을 적게하는 풀이다.(난 3개 선언, 아래는 2개 선언)
class Solution {
public int solution(int[] common) {
int answer = 0;
int x = common[1] - common[0];
int y = common[2] - common[1];
if (x == y) {
answer = common[common.length - 1] + y;
} else {
answer = common[common.length - 1] * common[2] / common[1];
}
return answer;
}
}
- 모든 코테가 이랬으면 좋겠다.
'흥미 > 코딩테스트' 카테고리의 다른 글
😊 #6 프로그래머스 - 7의 개수 (0) | 2023.02.07 |
---|---|
😊 #5 프로그래머스 - 잘라서 배열로 저장하기 (0) | 2023.02.06 |
😂 #4 프로그래머스 - 문자열 밀기(feat 로꾸거가 생각나는 노래) (0) | 2023.02.04 |
😂 #3 프로그래머스 - 종이 자르기 (0) | 2023.01.31 |
😂 #1 프로그래머스 - 옹알이 (0) | 2023.01.29 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- db
- MongoDB
- 자료구조
- 빅데이터
- Stream
- Phaser
- SpringBoot
- 코딩테스트
- Advanced Stream
- jpa
- 코테
- nosql
- node.js
- 빅데이터 분석기사
- API
- OS
- Spring Boot
- Java8
- 알고리즘
- 프로세스
- 메모리
- SQL
- DART
- 운영체제
- spring
- Phaser3
- 프로그래머스
- MySQL
- git
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함