언어공부/[BAEKJOON] C#
[ 프로그래머스 ] A로 B만들기_Lv.0
zzerou
2023. 2. 12. 18:09
https://school.programmers.co.kr/learn/courses/30/lessons/120886
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
using System;
public class Solution {
public int solution(string before, string after) {
int answer = 0;
char[] before_ = before.ToCharArray();
char[] after_ = after.ToCharArray();
Array.Sort(before_);
Array.Sort(after_);
string bbb = new string(before_);
string aaa = new string(after_);
if (bbb.Equals(aaa))
{
answer = 1;
}
else
{
answer = 0;
}
return answer;
}
}
----------------------------
using System;
using System.Collections.Generic;
public class Solution {
public int solution(string before, string after) {
int answer = 0;
List<char> b = new List<char> { };
List<char> a = new List<char> { };
foreach (char j in before)
{
b.Add(j);
b.Sort();
}
foreach (char j in after)
{
a.Add(j);
a.Sort();
}
string b1 = string.Join("", b);
string a1 = string.Join("", a);
if (b1 == a1)
{
answer = 1;
}
else
{
answer = 0;
}
return answer;
}
}
이렇게 두가지 방식을 쓸수있다고 한다