LeetCode 977. Squares of a Sorted Array

考点 难度
Sorting Easy
题目

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

思路

因为原数列是按照大小排序的,所以只需要比较首尾数字的平方。

答案
public int[] sortedSquares(int[] A) {int n = A.length;int[] result = new int[n];int i = 0, j = n - 1;for (int p = n - 1; p >= 0; p--) {if (Math.abs(A[i]) > Math.abs(A[j])) {result[p] = A[i] * A[i];i++;} else {result[p] = A[j] * A[j];j--;}}return result;
}

LeetCode知识点总结 - 977相关推荐

  1. LeetCode知识点总结 - 884

    LeetCode 884. Uncommon Words from Two Sentences 考点 难度 Hash Table Easy 题目 A sentence is a string of s ...

  2. LeetCode知识点总结 - 868

    LeetCode 868. Binary Gap 考点 难度 Math Easy 题目 Given a positive integer n, find and return the longest ...

  3. LeetCode知识点总结 - 1413

    LeetCode 1413. Minimum Value to Get Positive Step by Step Sum 考点 难度 Prefix Sum Easy 题目 Given an arra ...

  4. LeetCode知识点总结 - 2073

    LeetCode 2073. Time Needed to Buy Tickets 考点 难度 Simulation Easy 题目 There are n people in a line queu ...

  5. LeetCode知识点总结 - 347

    LeetCode 347. Top K Frequent Elements 考点 难度 Array Medium 题目 Given an integer array nums and an integ ...

  6. LeetCode知识点总结 - 997

    LeetCode 997. Find the Town Judge 考点 难度 Hash Table Easy 题目 In a town, there are n people labeled fro ...

  7. LeetCode知识点总结 - 606

    LeetCode 606. Construct String from Binary Tree 考点 难度 String Easy 题目 Given the root of a binary tree ...

  8. LeetCode知识点总结 - 844

    LeetCode 844. Backspace String Compare 考点 难度 Simulation Easy 题目 Given two strings s and t, return tr ...

  9. LeetCode知识点总结 - 377

    LeetCode 377. Combination Sum IV 考点 难度 DP Medium 题目 Given an array of distinct integers nums and a t ...

最新文章

  1. 【重磅】斯坦福李飞飞《注意力与Transformer》总结,84页ppt开放下载!
  2. AtCoder AGC038D Unique Path (图论)
  3. linux查看进程和线程的命令
  4. 基于pip的安装lxml库报错解决方案
  5. system函数和popen函数使用方法
  6. 【卡法电子商务】-常用手机屏幕尺寸 ★★★★★
  7. opencv-api filter2D
  8. CCF NOI1072 爬楼梯
  9. SharePoint快速调试技巧
  10. 九章算法系列(#2 Binary Search)-课堂笔记
  11. 上司:我们为什么要使用企业云盘?
  12. 如何写一个播放器-解析MNVideoPlayer(一)
  13. 硬盘出现c7导致计算机蓝屏,硬盘存在问题_硬盘存在问题c7
  14. 微信公众平台开发之微信红包的实现
  15. 笔记本电脑怎么给别人开热点
  16. AD软件绘制stm32最小系统电路原理图与PCB图
  17. 计算机入门 零基础,电脑新手入门指南——零基础一分钟入门电脑硬件
  18. 软考中级选哪个比较合适?
  19. Splay(dispatching)
  20. 时钟表24进制HTML,24进制数字电子钟时计器、译码显示电路 具有自动清零功能

热门文章

  1. mybatis与hibernate的对比
  2. mysql 5.6 不同步_MySQL5.6配置同步复制的新方法以及常见问题的解决方法
  3. 自学 Python 需要多长时间?
  4. shell 判断网线插拔_linux检测网线插拔状态
  5. LiveNVR传统IP摄像机接入-网页直播实现跨域鉴权
  6. ES设置自定义分词器
  7. 【mysql】drop、truncate和delete的区别
  8. 一篇就够,线程与线程池的那些事之线程池篇
  9. 2018-2019-2 20175227张雪莹《Java程序设计》实验三 《敏捷开发与XP实践》
  10. HTML中br标记和p标记区别,在 HTML 文档中,段落标记