[LeetCode] 88. Merge Sorted Array

2023. 3. 10. 15:01·Problem Solving/LeetCode

출처 : https://leetcode.com/problems/merge-sorted-array/

 

Merge Sorted Array - LeetCode

Can you solve this real interview question? Merge Sorted Array - You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 an

leetcode.com

 

 

 

 

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int A = m - 1; 
        int B = n - 1;
        int C = m + n - 1;
        while (A >= 0 && B >= 0) 
            nums1[C--] = (nums1[A] > nums2[B]) ? nums1[A--] : nums2[B--];
    
        while(B>=0) 
            nums1[C--] = nums2[B--];
    }
}
'Problem Solving/LeetCode' 카테고리의 다른 글
  • [LeetCode] 2811. Check if it is Possible to Split Array
  • [LeetCode] 33. Search in Rotated Sorted Array.
  • [LeetCode] 83. Remove Duplicates from Sorted List
  • [LeetCode] 94. Binary Tree Inorder Traversal
kimdozzi
kimdozzi
끝까지 포기하지 않으면, 내가 다 이겨!
  • kimdozzi
    도브로
    kimdozzi
  • 전체
    오늘
    어제
    • 분류 전체보기 (132)
      • Problem Solving (49)
        • Baekjoon (29)
        • Programmers (0)
        • LeetCode (17)
        • 삼성 유형 (2)
      • Computer Science (27)
        • Operating System (2)
        • Algorithms (13)
        • Network (6)
        • DataBase (6)
      • Backend (33)
        • JavaScript (0)
        • TypeScript (6)
        • Java (7)
        • Spring Boot (7)
        • Spring Security (6)
        • JPA (2)
        • Mybatis (1)
        • Junit5 (1)
        • Redis (3)
      • DevOps (14)
        • Git, Github (5)
        • docker (4)
        • AWS (3)
        • nginx (2)
      • etc (6)
        • IntelliJ (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 티스토리
    • 설정
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    segment tree
    점 업데이트
    docker image
    백준
    티스토리챌린지
    구간합
    컨테이너
    알고리즘
    누적합
    삼성기출
    오블완
    오프라인 쿼리
    인덱스 시그니처
    타입스크립트
    CORS
    도커
    인덱서블 타입
    온라인 쿼리
    imos법
    세그먼트 트리
    PrefixSum
    Bucket
    interface
    파이썬
    TypeScript
    인터페이스
    AWS
    구간 업데이트
    S3
    docker
    python
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
kimdozzi
[LeetCode] 88. Merge Sorted Array
상단으로

티스토리툴바