728x90
SMALL

 

C#

 

 

 

using System;

public class Solution {
    public string solution(string[] cards1, string[] cards2, string[] goal) {
        string answer = "Yes";
        int c1 = 0;
        int c2 = 0;
        
        for(int i = 0;i<goal.Length;i++)
        {
            if(c1 < cards1.Length && goal[i] == cards1[c1])
            {
                c1++;
            }
            else if(c2 < cards2.Length && goal[i] == cards2[c2])
            {
                c2++;
            }
            else
                return "No";      
        }
        
        return answer;
    }
}

 

 

 

////////////////////

 

 

 

자바

 

 

 

import java.io.*;

class Solution {
    public String solution(String[] cards1, String[] cards2, String[] goal) {
        int cardIdx1 = 0;
        int cardIdx2 = 0;

        for(int i=0; i<goal.length; i++)
        {
            String target = goal[i];

            if(cardIdx1 < cards1.length && target.equals(cards1[cardIdx1]))
                cardIdx1++;
            else if (cardIdx2 < cards2.length && target.equals(cards2[cardIdx2]))
                cardIdx2++;
            else
                return "No";
        }

        return "Yes";
    }
}
728x90

설정

트랙백

댓글