내적

문제 설명

자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요. 예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다.

 

제한 사항

 

  • n은 10,000,000,000이하인 자연수입니다.

 

 

 

입출력 예

n return
12345 [5,4,3,2,1]

 

Python

What is the meaning of “int(a[::-1])” in Python? [duplicate]

 

What is the meaning of "int(a[::-1])" in Python?

I cannot understand this. I have seen this in people's code. But cannot figure out what it does. This is in Python. str(int(a[::-1]))

stackoverflow.com

def solution(n):
    return [int(i) for i in str(n)][::-1]

JavaScript

function solution(a, b) {
    if(a.length != b.length)
        return -1;
    var answer = 0;
    for(let i = 0; i < a.length; i++){
        answer += a[i]*b[i];
    }
    return answer;
}

C++

#include <string>
#include <vector>

using namespace std;

vector<int> solution(long long n) {
    vector<int> answer;
    while(n){
        answer.push_back(n%10);
        n/=10;
    }
    return answer;
}
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기