From 6f0c66271d9bd878da967a578ca54dc60f899c2f Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Tue, 16 Jun 2020 09:15:12 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E6=95=B0=E7=BB=84=E7=9B=B8=E5=85=B3.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/数组相关.md | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/blogs/Algorithm/剑指 Offer/数组相关.md b/blogs/Algorithm/剑指 Offer/数组相关.md index 8cbe7dd..48a6279 100644 --- a/blogs/Algorithm/剑指 Offer/数组相关.md +++ b/blogs/Algorithm/剑指 Offer/数组相关.md @@ -17,6 +17,36 @@ class Solution { } ``` +```java +class Solution { + + public int findRepeatNumber(int[] nums) { + Arrays.sort(nums); + for (int i = 0; i < nums.length - 1; i++) { + if (nums[i] == nums[i + 1]) { + return nums[i]; + } + } + return -1; + } +} +``` + +```java +class Solution { + + public int findRepeatNumber(int[] nums) { + HashSet set = new HashSet<>(); + for (int i : nums) { + if (!set.add(i)) { + return i; + } + } + return -1; + } +} +``` + [04. 二维数组中的查找](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) ```java