https://school.programmers.co.kr/learn/courses/30/lessons/120922
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
시도 1)
class Solution {
public int solution(int M, int N) {
int answer = 0;
//가로
int cnt1 = M-1;
//세로
int cnt2 = (N-1)*2;
answer = cnt1+cnt2;
return answer;
}
}
정답
class Solution {
public int solution(int M, int N) {
int answer = 0;
answer = (M*N)-1;
return answer;
}
}
다른 사람의 풀이
class Solution {
public int solution(int M, int N) {
int cnt1 = M-1;
int cnt2 = (N-1)*M;
return cnt1 + cnt2;
}
}
'Java > 프로그래머스' 카테고리의 다른 글
[JAVA] 프로그래머스 - 문자열 내 p와 y의 개수 (0) | 2024.05.13 |
---|---|
[JAVA] 프로그래머스 - 다음에 올 숫자 (0) | 2024.05.12 |
[JAVA] 프로그래머스 - 문자열 밀기 (0) | 2024.05.12 |
[JAVA] 프로그래머스 - 연속된 수의 합 (0) | 2024.05.12 |
[JAVA] 프로그래머스 - k의 개수 (0) | 2024.05.12 |