hyelie
hyelie
Hyeil Jeong
       
글쓰기    관리    수식입력
  • 전체보기 (495)
    • PS (283)
      • Algorithm (28)
      • PS Log (244)
      • Contest (6)
      • Tips (5)
    • Development (52)
      • Java (14)
      • Spring (23)
      • SQL (2)
      • Node.js (2)
      • Socket.io (3)
      • Study (4)
      • Utils (4)
    • DevOps (36)
      • Git (5)
      • Docker (4)
      • Kubernetes (2)
      • GCP (3)
      • Environment Set Up (8)
      • Tutorial (12)
      • Figma (2)
    • CS (74)
      • OOP (7)
      • OS (24)
      • DB (2)
      • Network (24)
      • Architecture (0)
      • Security (2)
      • Software Design (0)
      • Parallel Computing (15)
    • Project (15)
      • Project N2T (5)
      • Project ASG (0)
      • Project Meerkat (1)
      • Model Checking (7)
      • Ideas (2)
    • 내가 하고싶은 것! (34)
      • Plan (16)
      • Software Maestro (10)
      • 취준 (8)
hELLO · Designed By 정상우.
hyelie

hyelie

PS/PS Log

23.04.17. 풀었던 문제들

Leetcode 1431. Kids With the Greatest Number of Candies

 설명할 필요도 없는 간단한 문제. candies[i]  + extraCandies가 max value of candies보다 크거나 같으면 extraCandies는 candies vector에서 max값이 될 수 있다.

// Runtime 0 ms Beats 100%
// Memory 8.9 MB Beats 86.24%

class Solution {
public:
    vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
        int n = candies.size();
        int maxCandies = *max_element(candies.begin(), candies.end());
        vector<bool> answer(n, false);
        for(int i = 0; i<n; i++){
            if(candies[i] + extraCandies >= maxCandies) answer[i] = true;
        }
        return answer;
    }
};

 

시간복잡도

 vector 순회 2번하므로 O(n)

 

공간복잡도

 answer vector 만드므로 O(n)

 

후기

 음... 요새 약간 PS에 투자하는 시간이 줄어든? 것 같은 느낌이 든다. 공부하는 시간이 그냥 준 걸지도. 내일부터 다시 공부하자!

 

 

 

 

저작자표시 (새창열림)

'PS > PS Log' 카테고리의 다른 글

23.04.19. 풀었던 문제들  (0) 2023.04.19
23.04.18. 풀었던 문제들  (0) 2023.04.18
23.04.16. 풀었던 문제들  (0) 2023.04.16
23.04.14. 풀었둔 문제들  (0) 2023.04.14
23.04.13. 풀었던 문제들  (0) 2023.04.13
    hyelie
    hyelie

    티스토리툴바