[抄题]:

We have some permutation A of [0, 1, ..., N - 1], where N is the length of A.

The number of (global) inversions is the number of i < j with 0 <= i < j < N and A[i] > A[j].

The number of local inversions is the number of i with 0 <= i < N and A[i] > A[i+1].

Return true if and only if the number of global inversions is equal to the number of local inversions.

Example 1:

Input: A = [1,0,2]
Output: true
Explanation: There is 1 global inversion, and 1 local inversion.

Example 2:

Input: A = [1,2,0]
Output: false
Explanation: There are 2 global inversions, and 1 local inversion.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

以为是n2扫2遍,结果不是啊

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

[一句话思路]:

global要向local靠拢,所以绝对值ai - i > 1就不行

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

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

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

[总结]:

global要向local靠拢,所以绝对值ai - i > 1就不行

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

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

[关键模板化代码]:

[其他解法]:

[Follow Up]:

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

[代码风格] :

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

[潜台词] :

class Solution {
public boolean isIdealPermutation(int[] A) {
for (int i = 0; i < A.length; i++)
if (Math.abs(A[i] - i) > 1)
return false;
return true;
}
}

775. Global and Local Inversions局部取反和全局取反的更多相关文章

  1. 【LeetCode】775. Global and Local Inversions 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/global-a ...

  2. 775. Global and Local Inversions

    We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  3. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions

    We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  4. [LeetCode] Global and Local Inversions 全局与局部的倒置

    We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  5. 【leetcode】Global and Local Inversions

    题目如下: We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (g ...

  6. 侧脸生成正脸概论与精析(一)Global and Local Perception GAN

    侧脸生成正脸我一直很感兴趣,老早就想把这块理一理的.今天来给大家分享一篇去年的老文章,如果有不对的地方,请斧正. Beyond Face Rotation: Global and Local Perc ...

  7. [leetcode-775-Global and Local Inversions]

    We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  8. oracle11.2中分区功能测试之add&amp;split partition对global&amp;local index的影响

    生产库中某些大表的分区异常,需要对现有表进行在线操作,以添加丢失分区,因为是生产库,还是谨慎点好,今天有空,针对add&split分区对global&local索引的影响进行了测试,测 ...

  9. 论文笔记:Improving Deep Visual Representation for Person Re-identification by Global and Local Image-language Association

    Improving Deep Visual Representation for Person Re-identification by Global and Local Image-language ...

随机推荐

  1. 09_组件三大属性(3)_refs和事件处理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. LeetCode 题解:Populating Next Right Pointers in Each Node I & II 二有难度。考虑不全面。

    每次应该把root同层的右侧节点传过来.如果没有,就传NULL. 同时,应该是先右后左. 感觉这次的代码还挺简洁的.. void construct(struct TreeLinkNode *root ...

  3. netty为啥要二次开发

    很早之前就看过李林峰写的netty的书,但是感觉没有直接用到还是理解不够深入,现在的公司有两套自己基于Netty开发的系统,感觉才真正理解为啥要这么做 借用别人文章回顾下 https://www.cn ...

  4. 用python实现一个简单的服务器

    打开命令行工具,输入: python3 -m http.server 8000(端口可以自己定) 通过访问:http://ip:8000/,就能给别人快速分享文件了.

  5. Haskell语言学习笔记(86)字符串格式化与插值

    String 的格式化 Text.Printf 这个模块用来处理字符串格式化. printf :: PrintfType r => String -> r printf 用于格式化字符串, ...

  6. echarts.js制作中国地图

    一.准备 1.  打开sublime,新建一个echarts文件夹,新建echarts.html文件 2.  在echarts.html文件中,为ECharts准备一个Dom(id是china-map ...

  7. Android通过adb命令Debug调试

    Android Debug后IDE执行的命令: / ::: Launching module_app $ adb push C:\fastwork\Projects\project\CJPT\modu ...

  8. Delphi实现悬浮的卡拉OK字幕

    千千静音的悬浮式卡拉OK字幕,大家一定觉得不错吧,其实用Delphi,你也可以很容易的做得到.首先我们在Delphi中新建一个700*130左右的窗体,上面放置两个Image控件,Image控件的Al ...

  9. jenkins 自动触发

    在gitlab上配置连接jenkins ,将Jenkins的Secret token 与Build URL 复制到gitlab中 在settings标签下面,找到OutBound Request,勾选 ...

  10. conductor编译镜像

    # git clone https://github.com/Netflix/conductor.git # git checkout -b 2.0 remotes/origin/2.0 # cd s ...