[Algorithm] 없는 숫자 더하기

2024. 12. 13. 10:25·Algorithm/Practice

문제 설명

0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다.

numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.

 

문제 유형

  • 완전 탐색

 

문제 해결 방법

  1. 수학적 방법
    1. 0부터 9까지의 합은 항상 45이다.
    2. 45에서 주어진 배열의 요소들을 마이너스하게되면 누락된 숫자들의 합을 구할 수 있다.

 

코드 작성

int solution(vector<int> numbers) {
    int result = 45;
    
    for (int number : numbers)
        result -= number;
    
    return result;
}

 

'Algorithm > Practice' 카테고리의 다른 글

[Algorithm] 나누어 떨어지는 숫자 배열  (0) 2024.12.14
[Algorithm] 서울에서 김서방 찾기  (0) 2024.12.14
[Algorithm] 핸드폰 번호 가리기  (1) 2024.12.13
[Algorithm] 음양 더하기  (1) 2024.12.13
[Algorithm] 콜라츠 추측  (0) 2024.12.12
'Algorithm/Practice' 카테고리의 다른 글
  • [Algorithm] 나누어 떨어지는 숫자 배열
  • [Algorithm] 서울에서 김서방 찾기
  • [Algorithm] 핸드폰 번호 가리기
  • [Algorithm] 음양 더하기
DevColIn
DevColIn
복잡함을 단순하게
  • DevColIn
    심플한 코딩생활
    복잡함을 단순하게
  • 전체
    오늘
    어제
    • 전체보기 (223)
      • Unreal 부트캠프 (49)
        • TIL (34)
        • 사전캠프 (7)
        • 본캠프 (8)
      • Unrael (10)
        • 환경설정 (0)
        • Basic (19)
        • Component (5)
        • GAS (GameplayAbilitySystem) (3)
        • AI (2)
        • Implement (10)
        • UI (1)
        • Error (1)
        • Network (2)
        • Tip (1)
      • Level Design (5)
      • Math (1)
      • Design Pattern (16)
      • Computer Science (2)
        • Network (1)
        • Database (1)
      • Algorithm (79)
        • Basic (4)
        • Practice (74)
      • C++ (4)
        • Basic (4)
      • Tool (0)
      • Game (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    디자인 패턴
    Design Pattern
    Algorithm
    Til
    tsoftobjectptr
    gas
    액터
    레벨디자인
    GameplayEffect
    게임동기화
    하드 레퍼런싱
    Animation
    basic
    사전캠프
    c++
    Implement
    소프트 레퍼런신
    unreal
    디자인패턴
    KPT회고
    unrealengine
    내일배움캠프
    assetmanager
    DesignPattern
    actor
    AI
    퀘스트
    component
    본캠프
    알고리즘
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
DevColIn
[Algorithm] 없는 숫자 더하기
상단으로

티스토리툴바