LCOV - code coverage report
Current view: top level - src/src - 2432.the-employee-that-worked-on-the-longest-task.cpp (source / functions) Coverage Total Hit
Test: _coverage_report.dat Lines: 100.0 % 19 19
Test Date: 2025-07-24 17:41:04 Functions: 100.0 % 5 5

            Line data    Source code
       1              : // Copyright (c) 2024 The Authors. All rights reserved.
       2              : //
       3              : // Licensed under the Apache License, Version 2.0 (the "License");
       4              : // you may not use this file except in compliance with the License.
       5              : // You may obtain a copy of the License at
       6              : //
       7              : //      https://www.apache.org/licenses/LICENSE-2.0
       8              : //
       9              : // Unless required by applicable law or agreed to in writing, software
      10              : // distributed under the License is distributed on an "AS IS" BASIS,
      11              : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12              : // See the License for the specific language governing permissions and
      13              : // limitations under the License.
      14              : 
      15              : // Authors: liubang (it.liubang@gmail.com)
      16              : 
      17              : 
      18              : #include <vector>
      19              : 
      20              : #include <gtest/gtest.h>
      21              : 
      22              : namespace {
      23              : class Solution {
      24              : public:
      25            4 :     int hardestWorker(int n, const std::vector<std::vector<int>>& logs) {
      26            4 :         int ret = logs[0][0];
      27            4 :         int max_time = logs[0][1];
      28           17 :         for (int i = 1; i < logs.size(); ++i) {
      29           13 :             int tmp = logs[i][1] - logs[i - 1][1];
      30           13 :             if (tmp == max_time)
      31            2 :                 ret = std::min(ret, logs[i][0]);
      32           11 :             else if (tmp > max_time) {
      33            3 :                 max_time = tmp;
      34            3 :                 ret = logs[i][0];
      35              :             }
      36              :         }
      37            4 :         return ret;
      38              :     }
      39              : };
      40              : } // namespace
      41              : 
      42            4 : TEST(Leetcode, leetcode) {
      43            1 :     Solution s;
      44            7 :     EXPECT_EQ(1, s.hardestWorker(10, {{0, 3}, {2, 5}, {0, 9}, {1, 15}}));
      45            7 :     EXPECT_EQ(3, s.hardestWorker(26, {{1, 1}, {3, 7}, {2, 12}, {7, 17}}));
      46            5 :     EXPECT_EQ(0, s.hardestWorker(2, {{0, 10}, {1, 20}}));
      47           10 :     EXPECT_EQ(
      48            1 :         12, s.hardestWorker(70, {{36, 3}, {1, 5}, {12, 8}, {25, 9}, {53, 11}, {29, 12}, {52, 14}}));
      49            9 : }
        

Generated by: LCOV version 2.0-1