[LeetCode] - Remove Element

2023. 8. 24. 16:50· 알고리즘/문제
목차
  1. 🔥 - Java 코드

https://leetcode.com/problems/remove-element/?envType=study-plan-v2&envId=top-interview-150

 

Remove Element - LeetCode

Can you solve this real interview question? Remove Element - Given an integer array nums and an integer val, remove all occurrences of val in nums in-place [https://en.wikipedia.org/wiki/In-place_algorithm]. The order of the elements may be changed. Then r

leetcode.com

 

📌 - 처음 생각한 풀이

 

📌- 풀이

  1. for문을 돌면서 num[i] 가 val이 아닐때
  2. count의 값에 해당하는 위치에 num[i]를 넣어주기

 

🔥 - Java 코드

 


  
import java.util.*;
class Solution {
public int removeElement(int[] nums, int val) {
int count =0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] != val) {
nums[count++] = nums[i];
}
}
return count;
}
}
  1. 🔥 - Java 코드
'알고리즘/문제' 카테고리의 다른 글
  • [LeetCode] - M - Remove Duplicates from Sorted Array II
  • [LeetCode] - Remove Duplicates from Sorted Array
  • [LeetCode] - Merge Sorted Array
  • [이분탐색] - S1_2343_기타레슨
Casteira
Casteira
할 뿐
Casteira
SpongeCake
Casteira
전체
오늘
어제
  • __Main__ (104)
    • 알고리즘 (65)
      • 개념 (6)
      • 문제 (58)
    • 컴퓨터 구조 (9)
      • 자료 구조 (2)
      • OS (7)
    • 웹 (1)
      • 자바 (1)
      • 스프링 (5)
      • SQL (0)
    • 기록 (4)
      • 포트폴리오 (2)
    • 정글 (18)
      • TIL (17)

블로그 메뉴

  • 🗒️ 깃허브
  • 태그
  • 방명록
  • 관리

공지사항

인기 글

태그

  • 크래프톤 정글
  • 백준 골드
  • annotation
  • 크래프톤
  • dp
  • framework
  • springboot
  • spring
  • 백준
  • 코딩테스트
  • java
  • 정글

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.1
Casteira
[LeetCode] - Remove Element
테마상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.