zoukankan      html  css  js  c++  java
  • 796. Rotate String旋转字符串

    [抄题]:

    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 1:
    Input: A = 'abcde', B = 'cdeab'
    Output: true
    
    Example 2:
    Input: A = 'abcde', B = 'abced'
    Output: false

     [暴力解法]:

    时间分析:

    空间分析:

     [优化后]:

    时间分析:

    空间分析:

    [奇葩输出条件]:

    [奇葩corner case]:

    [思维问题]:

    以为要用kmp:其实有时候简单拼一下就行了

    [英文数据结构或算法,为什么不用别的数据结构或算法]:

    [一句话思路]:

    [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

    [画图]:

    [一刷]:

    [二刷]:

    [三刷]:

    [四刷]:

    [五刷]:

      [五分钟肉眼debug的结果]:

    [总结]:

    [复杂度]:Time complexity: O(1) Space complexity: O(1)

    [算法思想:迭代/递归/分治/贪心]:

    [关键模板化代码]:

    [其他解法]:

    [Follow Up]:

    [LC给出的题目变变变]:

     [代码风格] :

     [是否头一次写此类driver funcion的代码] :

     [潜台词] :

    public boolean rotateString(String A, String B) {
        return A.length() == B.length() && (A + A).contains(B);
    }

     

  • 相关阅读:
    Linux服务器集群系统(一)--转
    linux文件操作命令--转
    HTTP Referer二三事---转
    Linux / Unix Command: bunzip2--reference
    SimpleUrlHandlerMapping 处理器映射的配置--转
    CSRF 攻击的应对之道--转
    Java 7之集合类型
    Flyweight_pattern--reference
    21 Free SEO Tools For Bloggers--reference
    存储在图的形式——邻接列表
  • 原文地址:https://www.cnblogs.com/immiao0319/p/9457745.html
Copyright © 2011-2022 走看看