Notice
Recent Posts
Recent Comments
Today
Total
01-11 01:45
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[LEETCODE] 1491. Average Salary Excluding the Minimum and Maximum Salary ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[LEETCODE] 1491. Average Salary Excluding the Minimum and Maximum Salary

WonderJay 2022. 10. 9. 15:36
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://leetcode.com/

TITLE : 1491.Average Salary Excluding the Minimum and Maximum Salary

Description : You are given an array ofuniqueintegerssalarywheresalary[i]is the salary of theithemployee.

Return the average salary of employees excluding the minimum and maximum salary. Answers within 10-5 of the actual answer will be accepted.

  • 3 <= salary.length <= 100
  • 1000 <= salary[i] <= 106
  • All the integers of salary are unique.

๋‹จ์ˆœํ•˜๊ฒŒ vector ์—์„œ ์ตœ๋Œ€, ์ตœ์†Œ ์›์†Œ๋ฅผ ์ œ์™ธํ•˜๊ณ  ํ‰๊ท ์„ ์‚ฐ์ถœํ•ด์„œ ๋ฆฌํ„ดํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.

 

[C++]

class Solution {
public:
	double average(vector<int>& salary) {
		double maxi = *max_element(salary.begin(), salary.end());
		double mini = *min_element(salary.begin(), salary.end());

		double ans = 0.0;
		for (int i = 0; i < salary.size(); i++) {
			ans += salary[i];
		}
		ans -= (maxi + mini);
		ans /= (salary.size() - 2);

		return ans;
	}
};

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments