saurus2
Saurus2
saurus2
전체 방문자
오늘
어제
  • 분류 전체보기
    • 개발
      • AJAX
    • ML Ops
    • Profile
    • 음식점
    • 배낭여행
    • 컴퓨터공학
      • 알고리즘 공부
      • C++
      • Sever 스터디
      • Java spring
      • 알고리즘 _ 문제해결
      • 딥러닝
      • Java 정리
      • Python
      • LeetCode 1000
      • Machine Learning Study
      • Sign language Detection Pro..
      • LeetCode Solutions
    • 비콘
    • 데일리 리포트
    • 유학일기
      • 영어 공부
      • Daily
    • AI Master Degree
      • Data Mining
      • AI and Data engineering
      • Math Foundations for Decisi..
      • Natural Language Processing

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • 온라인저지
  • 취준
  • 개발자 취업준비
  • LeetCode
  • 취업준비
  • 릿코드
  • BFS
  • 딕셔너리
  • 파이썬
  • Python
  • 백준
  • 문제해결능력
  • 알고리즘
  • 알고리즘문제해결
  • c++
  • two pointer
  • 리트코드
  • 개발자
  • 딥러닝
  • DFS

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
saurus2

Saurus2

컴퓨터공학/LeetCode 1000

[LeetCode] 796. Rotate String

2022. 11. 23. 07:24

796. Rotate String

Easy

Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.

A shift on s consists of moving the leftmost character of s to the rightmost position.

  • For example, if s = "abcde", then it will be "bcdea" after one shift.

 

Example 1:

Input: s = "abcde", goal = "cdeab"
Output: true

Example 2:

Input: s = "abcde", goal = "abced"
Output: false

 

Constraints:

  • 1 <= s.length, goal.length <= 100
  • s and goal consist of lowercase English letters.

문제 풀이

  • 문자를 한 글자씩 뒤로 보내서 goal에 들어있는 문자열과 같은지 확인하는 문제이다.
  • 리스트에 문자열을 넣고 앞에서 글자를 하나씩 뒤로 옮겨서 확인한 후 답을 반환한다.
  • 글자를 모두 이동 시켰지만 같은 문자열로 바뀌지 않는다면 마지막에 False를 반환한다. 

소스 코드

class Solution:
    def rotateString(self, s: str, goal: str) -> bool:
        lst = list(s)
        for i in range(len(s)):
            if ''.join(lst) == goal:
                return True
            lst.append(lst.pop(0))
        return False
저작자표시 (새창열림)

'컴퓨터공학 > LeetCode 1000' 카테고리의 다른 글

[LeetCode] 627. Swap Salary  (0) 2022.11.23
[LeetCode] 1873. Calculate Special Bonus  (0) 2022.11.23
[LeetCode] 487. Max Consecutive Ones II  (0) 2022.11.23
[LeetCode] 140. Word Break II  (0) 2022.11.14
[LeetCode] 139. Word Break  (1) 2022.11.11
    '컴퓨터공학/LeetCode 1000' 카테고리의 다른 글
    • [LeetCode] 627. Swap Salary
    • [LeetCode] 1873. Calculate Special Bonus
    • [LeetCode] 487. Max Consecutive Ones II
    • [LeetCode] 140. Word Break II
    saurus2
    saurus2
    Simple is Best

    티스토리툴바