728x90
SMALL

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i=1;i<=n;i++)
        {
            if(n%i == 0)
            {
                answer++;
            }
        }
        return answer;
    }
}

 

 

/////

자바

 

class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i = 1; i <= n; i++)
        {
            if(n % i == 0)
            {
                answer++;
            }
        }
        
        return answer;
    }
}

 

 

import java.util.stream.IntStream;

class Solution {
    public int solution(int n) {
        return (int) IntStream.rangeClosed(1, n).filter(i -> n % i == 0).count();
    }
}

 

파이썬

 

 

def solution(n):
    answer =0 
    for i in range(n):
        if n % (i+1) ==0:
            answer +=1
    return answer
728x90

설정

트랙백

댓글