[LeetCode] Length of Last Word (Python)

2025. 1. 15. 08:03·코딩 테스트
728x90

1.문제

https://leetcode.com/problems/length-of-last-word/description/?envType=study-plan-v2&envId=top-interview-150

 

2.풀이

공백을 기준으로 split 메소드를 사용하면 간단한 문제!

 

 

3.코드

class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        last_word = s.split()[-1]
        # print(last_word)
        return len(last_word)
728x90
저작자표시 비영리 변경금지 (새창열림)

'코딩 테스트' 카테고리의 다른 글

[LeetCode] Find the Index of the First Occurrence in a String (Python)  (0) 2025.01.15
[LeetCode] 14.Longest Common Prefix (Python)  (0) 2025.01.15
[LeetCode] Roman to Integer  (0) 2025.01.14
[LeetCode] In Subsequence (Python)  (0) 2025.01.13
[프로그래머스] 6주차 - 복서 정렬하기 (C++)  (0) 2021.09.08
'코딩 테스트' 카테고리의 다른 글
  • [LeetCode] Find the Index of the First Occurrence in a String (Python)
  • [LeetCode] 14.Longest Common Prefix (Python)
  • [LeetCode] Roman to Integer
  • [LeetCode] In Subsequence (Python)
zoodi
zoodi
IT/개발 관련 지식을 기록하는 블로그입니다.
  • zoodi
    오늘의 기록
    zoodi
  • 전체
    오늘
    어제
    • 분류 전체보기
      • 후기
        • 컨퍼런스
        • 일상리뷰
      • 금융경제
        • 뉴스
        • 금융IT용어
        • 경제 및 부동산
      • 코딩 테스트
      • 스터디
        • JAVA
        • Kotlin
        • Spring
        • React, Nextjs
        • 인공지능 AI
        • Cloud & k8s
        • Kafka
        • Database
        • Network
        • Algorithm
        • Hadoop
        • LINUX
        • R Programming
        • 기타 (소공, 보안)
      • 도서
      • 기타
  • 블로그 메뉴

    • 홈
    • 스터디
    • 금융경제
    • 후기
    • 기타
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    kafka
    codility
    카카오코테
    db
    Kotlin
    스프링부트
    네트워크
    C++
    프로그래머스
    알고리즘
    코딜리티
    LeetCode
    MySQL
    Spring
    자바
    금융용어
    코딩
    springboot
    코테
    java
    쿠버네티스
    자료구조
    코딩테스트
    pythoncodingtest
    이분탐색
    코테공부
    리트코드
    Python
    CodingTest
    스프링
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
zoodi
[LeetCode] Length of Last Word (Python)
상단으로

티스토리툴바