Easiest Java / C++ / C Solution (With Approach) 😎😎 -> 👌👌
Intuition\n Describe your first thoughts on how to solve this problem. \n- My first thought is to first calculate sum of digits of element the compare its value
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- My first thought is to first calculate sum of digits of element the compare its value with previous minimum number.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize three *int* `n=nums.length`, `sum` is for to calculate sum of digits of given element, in Java `mimum=Integer.MAX_VALUE`(in C++ `minimum=INT_MAX`) for to give maximum value of *int* data type.\n2. Start one `for` from *index=0* to *index<n* and everytime initialize `sum=0` for every element the sum of its digits starts from *0*.\n3. Use one `while` loop for to calculate sum of digits its use until `nums[index]!=0`, after loop check that which is smallest value `sum` or `minimum` and give it to `minimum`.\n4. At the end return `minimum`.\n\n# Complexity\n- Time complexity: $$O(n*log(M))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n \n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int minElement(int[] nums) {\n    int n=nums.length;\n    int sum, minimum=Integer.MAX_VALUE;\n\n        for(int i=0; i<n; i++){\n            sum=0;\n\n            while(nums[i]!=0){\n                sum=sum+nums[i]%10;\n                nums[i]=nums[i]/10;\n            }\n\n            minimum=Math.min(sum, minimum);\n        }\n\n        return minimum;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int minElement(vector<int>& nums) {\n    int n=nums.size();\n    int sum, minimum=INT_MAX;\n\n        for(int i=0; i<n; i++){\n            sum=0;\n\n            while(nums[i]!=0){\n                sum=sum+nums[i]%10;\n                nums[i]=nums[i]/10;\n            }\n\n            minimum=min(sum, minimum);\n        }\n\n    return minimum;\n    }\n};\n```\n```C []\nint minElement(int* nums, int numsSize) {\n    int sum, minimum=INT_MAX;\n\n        for(int i=0; i<numsSize; i++){\n            sum=0;\n\n            while(nums[i]!=0){\n                sum=sum+nums[i]%10;\n                nums[i]=nums[i]/10;\n            }\n\n            if(sum<minimum)\n            minimum=sum;\n        }\n\n    return minimum;\n}\n```\n
['C', 'C++', 'Java']