Post

[Programmers] #120898 - 편지 [Java][C++][Python]

[Programmers] #120898 - 편지 [Java][C++][Python]

문제 링크


1. 아이디어

문구를 한 줄로 적을 때 편지지의 최소 가로길이를 구하는 문제다. 글자 하나가 가로 2cm이고 공백도 한 글자로 치므로, 문구의 길이에 2를 곱한 값이 그대로 답이다.


2. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
class Solution {
    public int solution(String message) {
        return message.length() * 2;
    }
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;

int solution(string message) {
    return message.size() * 2;
}
1
2
def solution(message):
    return len(message) * 2

This post is licensed under CC BY 4.0 by the author.