Mapping and average


  • 0
    L

    public class Solution {

    public bool IsReflected(int[,] points) {
    
        Dictionary<int,List<int>> mapping = new Dictionary<int,List<int>>();
        
        int rows = points.GetLength(0);
        for(int i = 0;i<rows;i++)
        {
            if(!mapping.ContainsKey(points[i,1]))
                mapping.Add(points[i,1],new List<int>());
                
            mapping[points[i,1]].Add(points[i,0]);
        }
        double avg = double.MaxValue;
        
        foreach(var item in mapping)
        {
            if(avg == double.MaxValue)
            {
                avg = item.Value.Average();
            }else{
                double k = item.Value.Average();
                
                if(avg != k)
                    return false;
            }
        }
        
        return true;
    }
    

    }


Log in to reply
 

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