leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit dfe2a87c2b21fbaa2306b426a560fa3f82e3ea25
parent dc9e0141c5c62c928c5a2b8fa4e6e37e869ad3fe
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Mon,  1 May 2023 11:20:56 -0500

Completed mean of list problem using dart

Diffstat:
Aaverage-salary-excluding-min-and-max/average-salary.dart | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/average-salary-excluding-min-and-max/average-salary.dart b/average-salary-excluding-min-and-max/average-salary.dart @@ -0,0 +1,18 @@ +//Find the mean value of the list excluding the largest and smallest values. +//I solved this by sorting the list then iterating through excluding the first and last values. +//The time complexity of this code is O(nlog(n) where n is the number of values in the list. +//To optimize this solution I will complete it again iterating through the list one time instead of sorting first. +//Time: 268ms Beats: 57.69% +//Memory: 141.4MB Beats: 61.54% + +class Solution { + double average(List<int> salary) { + salary.sort(); + int total = 0; + for(int i = 1 ; i < salary.length - 1 ; ++i){ + total += salary[i]; + } + + return total / (salary.length - 2); + } +}