C# Accepted Beat 50%


  • 0
    S
    public class Solution {
    public IList<IList<int>> GetFactors(int n) {
        IList<int> temp = new List<int>();
        IList<IList<int>> result = new List<IList<int>>();
        if(n<4)return result;
        GetFactors(n,2,temp,result,n);
        return result;
    }
    
    public void GetFactors(int n,int factor,IList<int> temp, IList<IList<int>> result,int ori) {
        int sqrt = Convert.ToInt32(Math.Floor(Math.Sqrt(n)));
        if(factor>n)return;
        if(n!=ori){
            IList<int> temp1 = new List<int>(temp);
            temp1.Add(n);
            result.Add(temp1);
        }
        for(int i=factor;i<=sqrt;i++){
            if(n%i==0){
                IList<int> temp2 = new List<int>(temp);
                temp2.Add(i);
                GetFactors(n/i,i,temp2,result,ori);
            }
        }
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.