Best O(N) Solution
Approach\nOptimal Solution\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n    int sumOfSquares(v
# Approach\nOptimal Solution\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int sumOfSquares(vector<int>& nums) {\n        int n = nums.size();\n        int sum = 0;\n        for (int i = 1; i <= n; i++) {\n            if (n % i == 0) {\n                int sqr = nums[i-1] * nums[i-1];\n                sum += sqr;\n            }\n        }\n        return sum;\n    }\n};\n```
['C++']