题目链接 https://leetcode-cn.com/problems/sign-of-the-product-of-an-array/ 解题思路 按照题目要求去做即可 AC代码 class Solution { public int arraySign(int[] nums) { int ans = 1; for (int num : nums) { if (num == 0) return 0; ans *= (num > 0) ? 1 : -1; } return ans; } } 本地测试代码 package com.company; public class Solution_1822 { public static int arraySign(int[] nums) { int ans = 1; for (int num : nums) { if (num == 0) return 0; ans *= (num > 0) ? 1 : -1; } return ans; } public static void main(String[] args) { System.out.println(arraySign(new int[]{-1, -2, -3, -4, 3, 2, 1})); System.out.println(arraySign(new int[]{9, 72, 34, 29, -49, -22, -77, -17, -66, -75, -44, -30, -24})); } }