We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fce3f30 + ced3f8e commit 84e1fe9Copy full SHA for 84e1fe9
contains-duplicate/pastelto.java
@@ -0,0 +1,14 @@
1
+/*
2
+ Return true when array contains duplicated number
3
+ */
4
+class Solution {
5
+ public boolean containsDuplicate(int[] nums) {
6
+ HashSet<Integer> set = new HashSet<>();
7
+
8
+ for (int num : nums) {
9
+ if (set.contains(num)) return true;
10
+ set.add(num);
11
+ }
12
+ return false;
13
14
+}
two-sum/pastelto.java
@@ -0,0 +1,12 @@
+ public int[] twoSum(int[] nums, int target) {
+ for (int i = 0; i < nums.length - 1; i++) {
+ for (int j = i+1; j < nums.length; j++) {
+ if (nums[i] + nums[j] == target) {
+ return new int[]{i, j};
+ return new int[]{};
0 commit comments