Created
May 3, 2020 09:00
-
-
Save DongguemYoo/13a039f37dd7c579dc9b38391466d2ea to your computer and use it in GitHub Desktop.
코딩테스트 연습 자연수 뒤집어 배열로 만들기
This file contains 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 int[] solution(long n) | |
{ | |
char[] s = n.ToString().ToCharArray(); | |
int[] answer = new int[] { }; | |
answer = new int[s.Length]; | |
int x = 0; | |
for (int i = s.Length-1; i >=0; i--) | |
{ | |
answer[i] = int.Parse(s[x].ToString()); | |
x++; | |
} | |
return answer; | |
} | |
//다른사람이 푼 방식 | |
public int[] solution(long n) { | |
//여기서 Reverse로 뒤집어서 인덱스를 그대로 뿌리기만 하면 되게 만들었다 | |
string nString = new string(n.ToString().ToCharArray().Reverse().ToArray()); | |
int[] answer = new int[nString.Length]; | |
for (int i = 0; i < nString.Length; i++) | |
{ | |
answer[i] = int.Parse(nString[i].ToString()); | |
} | |
return answer; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment