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

2025. 3. 12. 11:12·CodingTest/LeetCode
반응형

1. 문제

  • 문자열 haystack, needle이 주어질 때, haystack 문자열 안에 needle이 존재하면, 시작 인덱스를 반환하고 없으면 -1을 반환하라.

2. 해결

function strStr(haystack: string, needle: string): number {    
    return haystack.indexOf(needle);
};
  • indexOf 함수를 이용해 해결할 수 있다.
저작자표시 (새창열림)
'CodingTest/LeetCode' 카테고리의 다른 글
  • [LeetCode] 344. Reverse String, Easy
  • [LeetCode] 14. Longest Common Prefix, Easy
  • [LeetCode] 67. Add Binary, Easy
  • [LeetCode] 118. Pascal's Triangle, Easy
뜸부깅
뜸부깅
코딩에 대한 여러 개인적인 생각을 정리하고 공부를 하는 공간입니다!!
  • 뜸부깅
    코오오딩
    뜸부깅
  • 전체
    오늘
    어제
    • Note (429)
      • Skill (31)
        • Java & Spring (9)
        • Javascript & HTML & CSS (0)
        • React (0)
        • Next.js (22)
      • CodingTest (389)
        • 백준 온라인 저지(BOJ) (140)
        • 프로그래머스(Programmers) (79)
        • LeetCode (170)
      • Algorithm & Data Structure (6)
      • [Project] 포트폴리오 (3)
        • Front end (3)
        • Back end (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    백준7576자바
    medium
    Easy
    백준2751
    BOJ
    프로그래머스
    알고리즘
    next 14
    leetcode 2236
    meidum
    백준
    자바
    백준1260
    백준1427
    boj1427
    백준7576
    TypeScript
    Java
    component-scan
    boj2108
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
뜸부깅
[LeetCode] 28. Find the Index of the First Occurrence in a String, Easy
상단으로

티스토리툴바