728x90
SMALL

using System;

public class Solution {
    public int solution(int[] sides) {
        int answer = 0;
        
        if(sides[0] > sides[1])
        {
            for(int i=sides[0]-sides[1]+1;i<sides[0]+sides[1];i++)
            {
                answer++;
            }
        }
        else
        {
            for(int j=sides[1]-sides[0]+1;j<sides[1]+sides[0];j++)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

////

 

 

using System;

public class Solution {
    public int solution(int[] sides) {
        int answer = 0;
        int max = (int)MathF.Max(sides[0], sides[1]);
        int total = sides[0] + sides[1];
        int min = total - max;
        return total-1-max+min;
    }
}

 

 

 

using System;
using System.Linq;
public class Solution {
    public int solution(int[] sides)
        {
            int answer = 0;
            int max = sides.Max();
            int min = sides.Min();

            for (int i = 1; i < max + min; i++)
            {
                if (max < i + min)
                {
                    answer++;
                }
            }
            return answer;
        }
}

 

 

자바

 

 

class Solution {
    public int solution(int[] sides) {
        int cnt = 0;
        for (int i = (sides[0]>sides[1]?sides[0]-sides[1]:sides[1]-sides[0])+1; i < sides[0] + sides[1]; i++)  cnt++;
        return cnt;
    }
}

 

 

class Solution {
    public int solution(int[] sides) {
            int min=Math.min(sides[0], sides[1]);
            int max=Math.max(sides[0], sides[1]);
            int sum=sides[0]+sides[1];
            int answer = 0;

            for(int i=1;i<sum;i++) 
            {
                if(i<=min || i<max)
                {//i가 중간값 또는 최솟값 
                    if(max<min+i) 
                    {
                        answer++;
                    }
                }
                else if(i>=max) {//i가 가장 긴 변이면
                    answer++;
                }
            }
            
            return answer;
        }
    }
728x90

설정

트랙백

댓글