Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 리액트 네이티브 시작하기
- SQL
- 자바
- HTTP
- 백준
- 정리
- 데베
- 깃허브 토큰 인증
- 모두를 위한 딥러닝
- 모두의네트워크
- 백준 4358번
- 깃허브 로그인
- 깃 터미널 연동
- 문자열
- 머신러닝
- 백준 5525번
- 네트워크
- 팀플회고
- 지네릭스
- 리액트 네이티브 프로젝트 생성
- 리액트 네이티브
- 스터디
- 모두의 네트워크
- 백준 4358 자바
- React Native
- 데이터베이스
- 딥러닝
- 백준 4949번
- 깃 연동
- 모두를위한딥러닝
Archives
- Today
- Total
솜이의 데브로그
[LeetCode] Remove Element (java) 본문
https://leetcode.com/problems/remove-element/
Remove Element - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제
풀이
새로운 배열을 생성하지 않고 기존에 있던 배열을 변경하는 방식으로 풀어야하는 문제다.
index를 따로 지정해주고, val 값이랑 일치하지 않는 경우에만 앞에서부터 배열에 넣어주는 방식으로 진행하고, 최종 index 값을 return 해주면 되는 간단한 문제이다.
코드
class Solution {
public int removeElement(int[] nums, int val) {
int index=0;
for(int i=0; i<nums.length; i++) {
if(nums[i] != val) {
nums[index++] = nums[i];
}
}
return index;
}
}
'Algorithm > LeetCode' 카테고리의 다른 글
[LeetCode] Zigzag Conversion (java) (0) | 2022.04.07 |
---|---|
[LeetCode] Two Sum (Java) (0) | 2022.04.07 |
[LeetCode] Roman to Integer (java) (0) | 2022.04.06 |