From 290e15e69e41d06f07c44ea70f01f009034c81cf Mon Sep 17 00:00:00 2001 From: yunskj Date: Tue, 9 Jul 2024 21:25:11 +0800 Subject: [PATCH] =?UTF-8?q?Update=200977.=E6=9C=89=E5=BA=8F=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E5=B9=B3=E6=96=B9.md=20=E5=A2=9E=E5=8A=A0Jav?= =?UTF-8?q?a=E6=8E=92=E5=BA=8F=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 977.有序数组的平方Java排序法 --- problems/0977.有序数组的平方.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md index b10620d0..7119dda5 100644 --- a/problems/0977.有序数组的平方.md +++ b/problems/0977.有序数组的平方.md @@ -100,6 +100,18 @@ public: ## 其他语言版本 ### Java: +排序法 +```Java +class Solution { + public int[] sortedSquares(int[] nums) { + for (int i = 0; i < nums.length; i++) { + nums[i] = nums[i] * nums[i]; + } + Arrays.sort(nums); + return nums; + } +} +``` ```Java class Solution {