diff --git a/leetcode-1431/src/com/aen/leetcode/Solution.java b/leetcode-1431/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..8eab221ca539342f1c520385fb0971899c75b903 --- /dev/null +++ b/leetcode-1431/src/com/aen/leetcode/Solution.java @@ -0,0 +1,28 @@ +package com.aen.leetcode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午3:32 + */ +public class Solution { + public List kidsWithCandies(int[] candies, int extraCandies) { + int max = 0; + int len = candies.length; + List candyList = new ArrayList<>(); + for (int i = 0; i < len; ++i) { + max = Math.max(max, candies[i]); + } + for (int i = 0; i < len; ++i) { + candyList.add(candies[i] + extraCandies >= max); + } + return candyList; + } +} diff --git a/leetcode-1431/src/com/aen/leetcode/SolutionTest.java b/leetcode-1431/src/com/aen/leetcode/SolutionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a3902da3f2a85e5ea0825903dabc9510b87726c3 --- /dev/null +++ b/leetcode-1431/src/com/aen/leetcode/SolutionTest.java @@ -0,0 +1,19 @@ +package com.aen.leetcode; + +import java.util.List; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午3:39 + */ +public class SolutionTest { + public static void main(String[] args) { + Solution solution = new Solution(); + List booleanList = solution.kidsWithCandies(new int[]{2, 3, 5, 1, 3}, 3); + System.out.println(booleanList); + } +} diff --git a/leetcode-1470/src/com/aen/leetcode/Solution.java b/leetcode-1470/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..e138b83ce00f26a512ebf648966fe55fe8652815 --- /dev/null +++ b/leetcode-1470/src/com/aen/leetcode/Solution.java @@ -0,0 +1,23 @@ +package com.aen.leetcode; + +/** + * Title: {@link Solution} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午3:06 + */ +public class Solution { + public int[] shuffle(int[] nums, int n) { + int len = nums.length; + int[] ints = new int[len]; + int j = 0; + for (int i = 0; i < n; ++i) { + ints[j] = nums[i]; + ints[j + 1] = nums[i + n]; + j += 2; + } + return ints; + } +} diff --git a/leetcode-1470/src/com/aen/leetcode/SolutionTest.java b/leetcode-1470/src/com/aen/leetcode/SolutionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..07ebcb6102d32ab5b785f2a4244bdea017dfe331 --- /dev/null +++ b/leetcode-1470/src/com/aen/leetcode/SolutionTest.java @@ -0,0 +1,20 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午3:30 + */ +public class SolutionTest { + public static void main(String[] args) { + int[] s = new int[]{2, 5, 1, 3, 4, 7}; + Solution solution = new Solution(); + int[] shuffle = solution.shuffle(s, 3); + for (int i : shuffle) { + System.out.println(i); + } + } +} diff --git a/leetcode-1480/src/com/aen/leetcode/Solution.java b/leetcode-1480/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..ef6f2b8dc9850ee7b56efcbef61efd49d6ec7cd2 --- /dev/null +++ b/leetcode-1480/src/com/aen/leetcode/Solution.java @@ -0,0 +1,23 @@ +package com.aen.leetcode; + +/** + * Title: {@link Solution} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午2:48 + */ +public class Solution { + + public int[] runningSum(int[] nums) { + int len = nums.length; + if (len <= 1){ + return nums; + } + for (int i = 1; i < len; ++i) { + nums[i] += nums[i -1]; + } + return nums; + } +} diff --git a/leetcode-1512/src/com/aen/leetcode/Solution.java b/leetcode-1512/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..fea1b6145f6263f2b87984bfb4fe195799997ffc --- /dev/null +++ b/leetcode-1512/src/com/aen/leetcode/Solution.java @@ -0,0 +1,53 @@ +package com.aen.leetcode; + +import java.util.HashMap; +import java.util.Map; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午4:02 + */ +public class Solution { + public int numIdenticalPairsOne(int[] nums) { + int len = nums.length; + int count = 0; + Map map = new HashMap<>(); + for (int i = 0; i < len; ++i) { + Integer integer = map.getOrDefault(nums[i], 0); + count += integer; + map.put(nums[i], integer + 1); + + } + return count; + } + + public int numIdenticalPairsTwo(int[] nums) { + int len = nums.length; + int count = 0; + for (int i = 0; i < len; ++i) { + for (int j = i + 1; j < len; ++j) { + if (nums[i] == nums[j]) { + ++count; + } + } + } + return count; + } + + public int numIdenticalPairsThree(int[] nums) { + int len = nums.length; + int count = 0; + int[] countArr = new int[100]; + for (int i = 0; i < len; ++i) { + count += countArr[nums[i]]; + ++countArr[nums[i]]; + } + return count; + } + + +} diff --git a/leetcode-1512/src/com/aen/leetcode/SolutionTest.java b/leetcode-1512/src/com/aen/leetcode/SolutionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a3b8bca27eedb0d3caabc0b0e53a9d34e59e46dc --- /dev/null +++ b/leetcode-1512/src/com/aen/leetcode/SolutionTest.java @@ -0,0 +1,17 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午4:02 + */ +public class SolutionTest { + public static void main(String[] args) { + Solution solution = new Solution(); + int i = solution.numIdenticalPairsThree(new int[]{1,1,1,1}); + System.out.println(i); + } +} diff --git a/leetcode-1603/src/com/aen/leetcode/ParkingSystem.java b/leetcode-1603/src/com/aen/leetcode/ParkingSystem.java new file mode 100644 index 0000000000000000000000000000000000000000..4b1b35f17a54b0c8f76d5ff78bcfc146aea90630 --- /dev/null +++ b/leetcode-1603/src/com/aen/leetcode/ParkingSystem.java @@ -0,0 +1,66 @@ +package com.aen.leetcode; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午4:48 + */ +public class ParkingSystem { + private Map map = new HashMap<>(); + + private int big; + private int medium; + private int small; + + + public ParkingSystem(int big, int medium, int small) { +// map.put(1, big); +// map.put(2, medium); +// map.put(3, small); + this.big = big; + this.medium = medium; + this.small = small; + } + + public boolean addCar(int carType) { + switch (carType) { + case 1: + if (big > 0) { + --big; + return true; + } + break; + case 2: + if (medium > 0) { + --medium; + return true; + } + break; + case 3: + if (small > 0) { + --small; + return true; + } + break; + } + return false; + } + +// public boolean addCar(int carType) { +// Integer integer = map.get(carType); +// if (integer > 0) { +// map.put(carType, integer-1); +// return true; +// } +// return false; +// } + + +} diff --git a/leetcode-1603/src/com/aen/leetcode/ParkingSystemTest.java b/leetcode-1603/src/com/aen/leetcode/ParkingSystemTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e66e6c793263ae6c6fb66f405bd3fb05447768f0 --- /dev/null +++ b/leetcode-1603/src/com/aen/leetcode/ParkingSystemTest.java @@ -0,0 +1,19 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午4:53 + */ +public class ParkingSystemTest { + public static void main(String[] args) { + ParkingSystem parkingSystem = new ParkingSystem(1,1,0); + System.out.println(parkingSystem.addCar(1)); + System.out.println(parkingSystem.addCar(2)); + System.out.println(parkingSystem.addCar(3)); + System.out.println(parkingSystem.addCar(1)); + } +} diff --git a/leetcode-771/src/com/aen/leetcode/Solution.java b/leetcode-771/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..c7cba344a55964725d17ad43a5c45619f3a3416b --- /dev/null +++ b/leetcode-771/src/com/aen/leetcode/Solution.java @@ -0,0 +1,40 @@ +package com.aen.leetcode; + +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午5:08 + */ +public class Solution { + + private Map map = new HashMap<>(); + + public int numJewelsInStones(String J, String S) { + int slen = S.length(); + int jlen = J.length(); + int count = 0; + for (int i = 0; i < slen; ++i) { + char s = S.charAt(i); + for (int j = 0; j < jlen; ++j) { + if (s == J.charAt(j)) { + count++; + } + } + } + return count; + } + + public void getMap(String J) { + int len = J.length(); + for (int i = 0; i < len; ++i) { + map.put(J.charAt(i), 1); + } + } +} diff --git a/leetcode-771/src/com/aen/leetcode/SolutionTest.java b/leetcode-771/src/com/aen/leetcode/SolutionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c368f131609f9452b76d20f1e49891824ee30789 --- /dev/null +++ b/leetcode-771/src/com/aen/leetcode/SolutionTest.java @@ -0,0 +1,18 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午5:39 + */ +public class SolutionTest { + + public static void main(String[] args) { + Solution solution = new Solution(); + int i = solution.numJewelsInStones("aA", "aAAbbbb"); + System.out.println(i); + } +} diff --git a/leetcode-844/src/com/aen/leetcode/Solution.java b/leetcode-844/src/com/aen/leetcode/Solution.java new file mode 100644 index 0000000000000000000000000000000000000000..48e039ab45d3c81a351fccc581e596f8fb2f2f09 --- /dev/null +++ b/leetcode-844/src/com/aen/leetcode/Solution.java @@ -0,0 +1,30 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午2:03 + */ +public class Solution { + public boolean backspaceCompare(String S, String T) { + return compare(S).equals(compare(T)); + } + + public String compare(String s) { + int len = s.length(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < len; i++) { + if (s.charAt(i) != '#') { + sb.append(s.charAt(i)); + } else { + if (sb.length() > 0) { + sb.deleteCharAt(sb.length() - 1); + } + } + } + return sb.toString(); + } +} diff --git a/leetcode-844/src/com/aen/leetcode/SolutionTest.java b/leetcode-844/src/com/aen/leetcode/SolutionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e42e09aa7104c05bc864fca74be7c29322b0a6e4 --- /dev/null +++ b/leetcode-844/src/com/aen/leetcode/SolutionTest.java @@ -0,0 +1,35 @@ +package com.aen.leetcode; + +/** + * Title: {@link com.aen.leetcode} + * Description: + * + * @author 谭 tmn + * @email AbelEthan@126.com + * @date 20-10-19 下午2:44 + */ +public class SolutionTest { + + public static void main(String[] args) { +// 输入:S = "ab#c", T = "ad#c" +// 输出:true +// 解释:S 和 T 都会变成 “ac”。 +// +// 输入:S = "ab##", T = "c#d#" +// 输出:true +// 解释:S 和 T 都会变成 “”。 +// +// 输入:S = "a##c", T = "#a#c" +// 输出:true +// 解释:S 和 T 都会变成 “c”。 +// +// 输入:S = "a#c", T = "b" +// 输出:false +// 解释:S 会变成 “c”,但 T 仍然是 “b”。 + Solution solution = new Solution(); + System.out.println(solution.backspaceCompare("ab#c", "ad#c")); + System.out.println(solution.backspaceCompare("ab##", "c#d#")); + System.out.println(solution.backspaceCompare("a##c", "#a#c")); + System.out.println(solution.backspaceCompare("a#c", "b")); + } +}