Programming/LeetCode

Programming/LeetCode

[Dart] LeetCode 28. Find the Index of the First Occurrence in a String

1. 문제 https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/description/?envType=study-plan-v2&envId=top-interview-150   2. 요구사항1) 두 개의 문자열 haystack과 needle이 주어진다.2) haystack에서 needle과 같은 문자열이 있는 경우에 처음 나타나는 인덱스를 반환한다.3) 만약 일치하는 문자열이 없는 경우에는 -1을 반환한다.  3. 핵심 아이디어1) substring으로 문자열 나누기 haystack을 needle과 비교하기 위해서 needle과 같은 문자열로 나눈 후, 비교해야 합니다. str.substring(i, j)는 str 문..

Programming/LeetCode

[Dart] LeetCode 27. Remove Element

1. 문제https://leetcode.com/problems/remove-element/description/?envType=study-plan-v2&envId=top-interview-150  2. 요구사항1) 배열 nums에서 val과 같은 값을 제거합니다.2) 배열의 순서는 변경될 수 있습니다.3) val이 아닌 원소들로 이루어진 새로운 길이 k를 반환합니다.4) nums의 첫 k개 요소는 val이 아닌 값으로 채워져 있어야 합니다.5) 배열의 나머지 요소는 중요하지 않습니다. (어떤 값이 남아도 괜찮음)  3. 핵심 아이디어1) Two Pointer두 개의 포인터를 사용하여 값을 이동합니다. 첫 번째 포인터는 배열을 순회하며, 현재 검사중인 요소를 가리킵니다.두 번째 포인터는 val이 아닌 값을..

Meezzi
'Programming/LeetCode' 카테고리의 글 목록 (9 Page)