码迷,mamicode.com
首页 > 其他好文 > 详细

String1 is rotating match for

时间:2017-12-07 14:56:37      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:contain   har   arp   next   cab   contains   write   foo   span   

 

String Rotation. Given two string check if String1 is rotating match for String2

 

# Given two strings. Write a function that will return true if one string is a rotation of the other string.
# e.g. ‘bca‘ and ‘cab‘ are rotations of ‘abc‘ and the function should return true
# ‘barbazfoo‘, ‘oobarbazf‘ and ‘rbazfooba‘ are rotations of ‘foobarbaz‘

def is_rotation(string1, string2):
import java.util.Scanner;

public class StringCheck {
	
	public static void main(String[] args) {

		Scanner scan=new Scanner(System.in);
		String s1=scan.next();
		String s2=scan.next();
		String s=s2+s2;
		if (s1.length() == s2.length()){
			return s.contains(s1);
		} else {
			return false;
		}
}

}

  

String1 is rotating match for

标签:contain   har   arp   next   cab   contains   write   foo   span   

原文地址:http://www.cnblogs.com/apanda009/p/7998630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!