Q1. Rotate String(796)

We are given two strings, A and B.

shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, if A = 'abcde', then it will be 'bcdea' after one shift on A. Return True if and only if A can become B after some number of shifts on A.

Example :
Input: A = 'abcde', B = 'cdeab'
Output: true Example :
Input: A = 'abcde', B = 'abced'
Output: false

Note:

  • A and B will have length at most 100.
 class Solution {
public:
bool rotateString(string A, string B) {
if(A.size() != B.size())
return false; for( int i = ; i < A.size(); i++)
bool ok = true;
for(int j = ; j < B.size(); j++)
if(A[(i + j) % A.size()] != B[j]) {
ok = false;
break;
}
if(ok) {
return true;
}
return false;
}
};

Weekly Contest 75题解的更多相关文章

  1. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  2. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  3. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  4. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  5. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  6. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  7. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. M-SOLUTIONS Programming Contest 2020 题解

    M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...

随机推荐

  1. 启动eclipse时出现“Failed to load the JNI shared library jvm.dll”错误及解决

    昨晚安装另一个版本的eclipse,启动时出现了"Failed to load the JNI shared library jvm.dll"错误: 1.刚开始以为是因为当时没有将 ...

  2. 安装nodejs时:The error code is 2503.

    在windows下安装nodejs时老是报错: The installer has encountered an unexpected error installing . 有三种方法可以尝试: &q ...

  3. Java练习(模拟扫雷游戏)

    要为扫雷游戏布置地雷,扫雷游戏的扫雷面板可以用二维int数组表示.如某位置为地雷,则该位置用数字-1表示, 如该位置不是地雷,则暂时用数字0表示. 编写程序完成在该二维数组中随机布雷的操作,程序读入3 ...

  4. 在删除一个指针之后,一定将该指针设置成空指针(即在delete *p之后一定要加上: p=NULL)

    在删除一个指针之后,一定将该指针设置成空指针(即在delete *p之后一定要加上: p=NULL)

  5. wpf的tab移动焦点只能在容器内部使用

    设置 KeyboardNavigation.TabNavigation="Cycle" 即可

  6. [论文阅读] A Discriminative Feature Learning Approach for Deep Face Recognition (Center Loss)

    原文: A Discriminative Feature Learning Approach for Deep Face Recognition 用于人脸识别的center loss. 1)同时学习每 ...

  7. flask开发用户管理系统wtf版

    #coding=utf-8 from flask import Flask from flask import request from flask import redirect from flas ...

  8. requests-post请求

    post与get方法的区别在于post需要提交一些数据以备处理. 在requests里面非常简单,headers,data都是直接加进去就可以了 # requests.post提交表单# 有些网站使用 ...

  9. [LeetCode] Design Compressed String Iterator 设计压缩字符串的迭代器

    Design and implement a data structure for a compressed string iterator. It should support the follow ...

  10. 【django小练习之主机管理界面】

    需求: 利用django,js,bootstrap等实现登录,主机管理等操作. 实现截图 登录界面 主机界面,添加及编辑 部门管理界面 代码实现 目录层级 settings.py "&quo ...