728x90
SMALL

using System;

public class Solution {
    public int solution(int[] absolutes, bool[] signs) {
        int answer = 0;
        
        for(int i = 0;i<absolutes.Length;i++)
        {
            if(signs[i] == true)
            {
                answer += absolutes[i];
            }
            else
            {
                answer += -1 * absolutes[i];
            }
        }
        
        return answer;
    }
}

 

////////

 

파이썬

 

def solution(absolutes, signs):
    answer=0
    for absolute,sign in zip(absolutes,signs):
        if sign:
            answer+=absolute
        else:
            answer-=absolute
    return answer

 

자바

//////

 

 

class Solution {
    public int solution(int[] absolutes, boolean[] signs) {
        int answer = 0;
        
        for (int i=0; i<signs.length; i++)
            answer += absolutes[i] * (signs[i]? 1: -1);
        
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;
using System.Linq;

public class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Array.Sort(citations);
        Array.Reverse(citations);
        
        for(int i = 0;i<citations.Length;i++)
        {
            if(citations[i] >= i+1)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

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

 

//이건 아무리 봐도 설명이 부실했다. 예에 나온 것처럼 [3, 0, 6, 1, 5] 일때 인용이 많은 순서대로 정렬한 [6,5,3,1,0]에서 0번째 인덱스는 1보다 커야하고 1번째 인덱스는 2보다 커야하는 식으로

 

///내림차순으로 정렬된 어레이에서 처음부터 i 번째 어레이의 인덱스가 i+1보다 크지 않은 첫 번째 경우가 나올 때까지의 갯수를 구하는 건데 약간 설명이 애매하게 돼 있다. 

 

 

파이썬

 

def solution(citations):
    citations.sort(reverse=True)
    answer = max(map(min, enumerate(citations, start=1)))
    return answer

 

/////

 

 

def solution(citations):
    citations = sorted(citations)
    l = len(citations)
    for i in range(l):
        if citations[i] >= l-i:
            return l-i
    return 0

 

 

자바

 

 

import java.util.Arrays;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Arrays.sort(citations);
        
        for(int i=0; i<citations.length; i++)
        {
            int smaller = Math.min(citations[i], citations.length-i);
            answer = Math.max(answer, smaller);
        }
        
        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = new int[numbers.Length];
        
        for(int i=0;i<numbers.Length;i++)
            answer[i] = numbers[i] * 2;
        return answer;
    }
}

 

/////

 

파이썬

 

/////

def solution(numbers):
    return [num*2 for num in numbers]

 

자바

 

class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = {};
        answer = new int[numbers.length];
        
        for(int i=0; i<answer.length; i++)
        {
            answer[i] = numbers[i]*2;
        }
        
        return answer;
    }
}

 

 

import java.util.*;

class Solution {
    public ArrayList solution(int[] numbers) {
        ArrayList<Integer> answer = new ArrayList<>();

        for(int num : numbers)
        {
            answer.add(num*2);
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int num1, int num2) {
        int answer = num1/num2;
        return answer;
    }
}

 

 

파이썬

def solution(num1, num2):
    return num1 // num2

////////

solution = int.__floordiv__

 

JAVA

 

class Solution {
    public int solution(int num1, int num2) {
        return num1/num2;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int[] solution(string s) {
        int[] answer = new int[2]; 
        int index = 0;
        int i = 0;
        
        while(s != "1")
        {
            int length = s.Length;
            s = s.Replace("0", "");
            index++;
            length = length - s.Length;
            i += length;
            s = Convert.ToString(s.Length, 2);
        }
        
        answer[0] = index;
        answer[1] = i;
        
        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] a, int[] b) {
        int answer = 0;
        
        for(int i =0;i<a.Length;i++)
        {
            answer += a[i] * b[i];
        }
        return answer;
    }
}

728x90

설정

트랙백

댓글

728x90
SMALL

public class Solution {
    public string[] solution(string[] quiz) {
        string[] answer = new string[quiz.Length];
        
        for(int i = 0; i < quiz.Length; i++)
        {
            answer[i] = oxCheck(quiz[i].Split(" "));
        }
        return answer;
    }
    
    public string oxCheck(string[] str)
    {
        int num = int.Parse(str[0]);

/// 첫 번째 숫자
        
        for(int i = 1; i < str.Length; i++) // 1부터 한다.
        {

///홀수 번째 일때는 연산자니까 
            if(i % 2 != 0)
            {
                if(str[i].Equals("+"))
                {
                    num += int.Parse(str[i + 1]);

/// 플러스면 더하고
                }
                else if(str[i].Equals("-"))
                {
                    num -= int.Parse(str[i + 1]);

/// 마이너스면 뺀다.
                }
                else
                {
                    if(int.Parse(str[i + 1]) == num)
                    {
                        return "O";
                    }
                    else
                    {
                        return "X";
                    }
                }
            }
        }
        
        return "";
    }
}

 

 

 

 

자바

 

 

 

class Solution {
    public String[] solution(String[] quiz) {

        int size = quiz.length;
        String[] answer = new String[size];
        
        for (int i = 0; i < answer.length; i++) 
        {
            String[] splitQ = quiz[i].trim().split(" ");
            int X = Integer.parseInt(splitQ[0]);
            int Y = Integer.parseInt(splitQ[2]);
            int Z = Integer.parseInt(splitQ[4]);
            int cal = 0;
            
            if(splitQ[1].equals("-"))
            {
                cal = X - Y;
            }
            else
            {
                cal = X + Y;
            }

            answer[i] = Z == cal ? "O" : "X";
        }

        return answer;
    }
}

 

 

 

 

class Solution {
    public String[] solution(String[] quiz) {
        String[] answer = new String[quiz.length];

        for(int i=0; i<quiz.length; i++)
        {
            String[] temp = quiz[i].split(" ");
            
            if(temp[0].isEmpty())
            {
                answer[i]="O";
                continue; 
            }
            
            Integer first = Integer.parseInt(temp[0]);
            String oper = temp[1];
            Long second = Long.parseLong(temp[2]);
            Integer result = Integer.parseInt(temp[4]);

            if(oper.equals("+"))
            {
                if(first+second==result)
                {
                    answer[i] = "O";
                } 
                else 
                {
                    answer[i] = "X";
                }
            } 
            else 
            {
                if(first-second==result)
                {
                    answer[i] = "O";
                } 
                else 
                {
                    answer[i] = "X";
                }
            }

        }


        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

class Solution
{
    public int[] solution(int[,] v)
    {
        int[] answer={0,0};

        answer[0] = v[0,0] ^ v[1,0] ^ v[2,0];
        answer[1] = v[0,1] ^ v[1,1] ^ v[2,1];

        return answer;
    }
}

///////

 

    int[] answer = new int[2];

    for(int i=0; i<answer.Length;i++)

    {

        if(v[0][i] == v[1][i])

        {

             answer = v[2][i];

        }

        else if(v[0][i] == v[2][i])

        {

             answer = v[1][i];

        }

        else if(v[1][i] == v[2][i])

        {

             answer = v[0][i];

        }

   }

   return answer;

 

A XOR B = 0

A XOR A XOR B = B 

같은 값 두개와 다른 값 하나를 XOR하면 다른 값 한개가 나옴

728x90

설정

트랙백

댓글