프로그래머스 알고리즘/코딩 테스트 문제
C# 프로그래머스 [Level 1] _자연수 뒤집어 배열로 만들기
재호우96
2020. 5. 26. 23:41
반응형
C# 프로그래머스 [Level 1] _문제이름

https://programmers.co.kr/learn/courses/30/lessons/12932
코딩테스트 연습 - 자연수 뒤집어 배열로 만들기
자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요. 예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다. 제한 조건 n은 10,000,000,000이하인 자연수입니다. 입출력 예 n return 12345
programmers.co.kr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution | |
{ | |
public long[] solution(long n) | |
{ | |
long temp = n; | |
string input = n.ToString(); | |
long[] arr = new long[input.Length]; | |
//WriteLine("길이 : " + input.Length); | |
for (int index = 0; index < arr.Length; index++) | |
{ | |
arr[index] = temp % 10; | |
temp /= 10; | |
//WriteLine("arr[index] : " + arr[index]); | |
//WriteLine("temp : " + temp); | |
} | |
return arr; | |
} | |
} |
반응형