diff --git a/Week_02/id_5/LeetCode_1_05.java b/Week_02/id_5/LeetCode_1_05.java new file mode 100644 index 00000000..2db8ac60 --- /dev/null +++ b/Week_02/id_5/LeetCode_1_05.java @@ -0,0 +1,28 @@ +import java.util.HashMap; +import java.util.Map; + +public class LeetCode_1_05 { + + /** + * 两数之和 + * - 做这个题的时候,已经做了三数之和了。 + * - 那我就不再使用枚举的方法了 + * - + * @param nums + * @param target + * @return + */ + public int[] twoSum(int[] nums, int target) { + Map book = new HashMap<>(); + for (int i = 0;i window = new HashSet<>(); + int i = 0, j = 0, maxLength = 0; + + while (i < length && j < length) { + if (!window.contains(s.charAt(j))) { + window.add(s.charAt(j)); + j++; + maxLength = Math.max(maxLength, j - i); + }else{ + window.remove(s.charAt(i)); + i++; + } + } + return maxLength; + } + +}