c# recursive solution


  • 0
    N
    public class Solution {
        public string FindContestMatch(int n) {
            var arr = new string[n];
            for(var i=1;i<=n;i++){
                arr[i-1] = i.ToString();
            }
            
            return Math(arr);
        }
        
        public string Math(string[] arr){
            if(arr.Length==1) return arr[0];
            
            var sub = new string[arr.Length/2];
            for(var i=0;i<sub.Length;i++){
                sub[i] = string.Format("({0},{1})", arr[i], arr[arr.Length-1-i]);
            }
            
            return Math(sub);
        }
    }
    

Log in to reply
 

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