"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings

"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings

table of contents

CHAP1. Arrays and strings

  1. Unique string
  2. Count the number of the same characters
  3. URLify
  4. Palindrome permutation
  5. One-shot conversion
  6. String compression
  7. Rotate matrix
  8. Matrix of "0"
  9. Rotate string

Python code answer example

def isSubstring(s1,s2):

    return s2 in s1

def isRotation(s1,s2):

    length = len(s1)

    if length==len(s2) and length>0:
        s1s1 = s1 + s1  
        return isSubstring(s1s1,s2)

    return False

input_str_1 = "waterbottle"
input_str_2 = "bottlewater"

print(isRotation(input_str_1,input_str_2))

input_str_3 = "waterbottle"
input_str_4 = "water"

print(isRotation(input_str_3,input_str_4))

Recommended Posts

"A book to train programming skills to fight in the world" Python code answer example --1.9 Rotation of strings
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
"A book to train programming skills to fight in the world" Python code answer example --3.1 Three stacks
"A book to train programming skills to fight in the world" Python code Solution example --1.7 Matrix rotation
"Book to train programming skills to fight in the world" Python code answer example --1.4 Permutation of sentences
"Book to train programming skills to fight in the world" Python code answer example --1.3 URLify
"Book to train programming skills to fight in the world" Python code answer example --2.6 palindrome
"A book to train programming skills to fight in the world" Python code answer example --1.2 Count the number of the same characters
"A book to train programming skills to fight in the world" Python code answer example --1.1 Duplicate character string
"Book to train programming skills to fight in the world" Python code answer example --2.4 Splitting the list
"Book to train programming skills to fight in the world" Python code answer example --2.7 intersecting nodes
"A book to train programming skills to fight in the world" Python code answer example --2.2 Returns the Kth from the back
"A book to train programming skills to fight in the world" Python code Solution example --1.6 String compression
"A book to train programming skills to fight in the world" Python code solution example --1.5 One-shot conversion
"A book to train programming skills to fight in the world" Python code Solution example --2.8 Loop detection
"A book to train programming skills to fight in the world" Python code Solution example --2.5 The sum of two numbers shown in the list
"Book to train programming skills to fight in the world" Python code solution example --- Removed elements between 2.3
"Book to train programming skills to fight in the world" Python code Solution example --2.1 Remove duplicate elements
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Programming to fight in the world ~ 5-2
An example of the answer to the reference question of the study session. In python.
[Kenchon book to Python] "Train your problem-solving skills! Algorithms and data structures" I tried to rewrite the posted code in Python! -table of contents-
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
Programming to fight in the world-Chapter 4
How to determine the existence of a selenium element in Python
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
How to check the memory size of a variable in Python
I wrote the code to write the code of Brainf * ck in python
How to check the memory size of a dictionary in Python
What kind of book is the best-selling "Python Crash Course" in the world?
Python code to determine the monthly signal of a relative strength investment
I made a program to check the size of a file in Python
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
Various ways to read the last line of a csv file in Python
How to pass the execution result of a shell command in a list in Python
Get the caller of a function in Python
[Kenchon book to Python]-Chapter 3- "Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
Make a copy of the list in Python
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I searched for the skills needed to become a web engineer in Python
Output in the form of a python array
[Kenchon book to Python]-Chapter 2- "Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
[Kenchon book to Python]-Chapter 4-"Train your problem-solving skills! Algorithms and data structures" I rewrote the posted code to Python!
How to get a list of files in the same directory with python
Run the output code with tkinter, saying "A, pretending to be B" in python
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
I used Python to find out about the role choices of the 51 "Yachts" in the world.
A story about trying to introduce Linter in the middle of a Python (Flask) project
Try to solve the programming challenge book with python3
How to get the number of digits in Python
A collection of code often used in personal Python
Reproduce the execution example of Chapter 4 of Hajipata in Python
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)
A reminder about the implementation of recommendations in Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Python Note: The mystery of assigning a variable to a variable