Skip to content

Commit 1a47bf1

Browse files
a
1 parent b3b46dc commit 1a47bf1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@
907907
| 3114 | [Latest Time You Can Obtain After Replacing Characters](https://leetcode.com/problems/latest-time-you-can-obtain-after-replacing-characters) | [![Java](assets/java.png)](src/LatestTimeYouCanObtainAfterReplacingCharacters.java) | |
908908
| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i) | [![Java](assets/java.png)](src/CountTheNumberOfSpecialCharactersI.java) | |
909909
| 3127 | [Make a Square with the Same Color](https://leetcode.com/problems/make-a-square-with-the-same-color) | [![Java](assets/java.png)](src/MakeASquareWithTheSameColor.java) | |
910-
| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | | |
910+
| 3131 | [Find the Integer Added to Array I](https://leetcode.com/problems/find-the-integer-added-to-array-i) | [![Java](assets/java.png)](src/FindTheIntegerAddedToArrayI.java) | |
911911
| 3136 | [Valid Word](https://leetcode.com/problems/valid-word) | | |
912912
| 3142 | [Check if Grid Satisfies Conditions](https://leetcode.com/problems/check-if-grid-satisfies-conditions) | | |
913913
| 3146 | [Permutation Difference between Two Strings](https://leetcode.com/problems/permutation-difference-between-two-strings) | | |

src/FindTheIntegerAddedToArrayI.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://leetcode.com/problems/find-the-integer-added-to-array-i
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class FindTheIntegerAddedToArrayI {
6+
public int addedInteger(int[] array1, int[] array2) {
7+
final int min1 = smallestElement(array1);
8+
final int min2 = smallestElement(array2);
9+
return min2 - min1;
10+
}
11+
12+
private static int smallestElement(int[] array) {
13+
int result = Integer.MAX_VALUE;
14+
for (int element : array) {
15+
result = Math.min(result, element);
16+
}
17+
return result;
18+
}
19+
}

0 commit comments

Comments
 (0)