From ffe16bf6dd24544dc0e782c5dee79a7f85710ffe Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Thu, 4 Jul 2024 08:50:35 +0200 Subject: [PATCH] Prepare for publication --- .../leetcode/lc0/lc0000/Problem0001.java | 4 +- .../leetcode/lc0/lc0000/Problem0011.java | 29 +-- .../leetcode/lc0/lc0000/Problem0012.java | 73 +------ .../leetcode/lc0/lc0000/Problem0015.java | 34 +--- .../leetcode/lc0/lc0000/Problem0017.java | 52 +---- .../leetcode/lc0/lc0000/Problem0018.java | 33 +-- .../leetcode/lc0/lc0000/Problem0020.java | 37 ---- .../leetcode/lc0/lc0000/Problem0024.java | 2 +- .../leetcode/lc0/lc0000/Problem0035.java | 28 +-- .../leetcode/lc0/lc0000/Problem0067.java | 28 +-- .../leetcode/lc0/lc0000/Problem0070.java | 15 -- .../leetcode/lc0/lc0000/Problem0071.java | 29 +-- .../leetcode/lc0/lc0000/Problem0077.java | 7 +- .../leetcode/lc0/lc0000/Problem0086.java | 2 +- .../leetcode/lc0/lc0000/Problem0087.java | 102 +--------- .../leetcode/lc0/lc0000/Problem0099.java | 4 +- .../leetcode/lc0/lc0100/Problem0121.java | 21 +- .../leetcode/lc0/lc0100/Problem0124.java | 19 +- .../leetcode/lc0/lc0100/Problem0134.java | 2 +- .../leetcode/lc0/lc0100/Problem0136.java | 19 -- .../leetcode/lc0/lc0100/Problem0137.java | 21 +- .../leetcode/lc0/lc0100/Problem0169.java | 20 +- .../leetcode/lc0/lc0100/Problem0170.java | 43 ---- .../leetcode/lc0/lc0100/Problem0179.java | 27 +-- .../leetcode/lc0/lc0100/Problem0190.java | 6 - .../leetcode/lc0/lc0100/Problem0191.java | 12 -- .../leetcode/lc0/lc0200/Problem0206.java | 25 --- .../leetcode/lc0/lc0200/Problem0207.java | 4 +- .../leetcode/lc0/lc0200/Problem0212.java | 2 +- .../leetcode/lc0/lc0200/Problem0214.java | 5 +- .../leetcode/lc0/lc0200/Problem0231.java | 11 +- .../leetcode/lc0/lc0200/Problem0239.java | 9 - .../leetcode/lc0/lc0200/Problem0248.java | 4 +- .../leetcode/lc0/lc0200/Problem0271.java | 2 +- .../leetcode/lc0/lc0200/Problem0273.java | 4 +- .../leetcode/lc0/lc0200/Problem0278.java | 4 +- .../leetcode/lc0/lc0200/Problem0286.java | 2 +- .../leetcode/lc0/lc0200/Problem0298.java | 4 +- .../leetcode/lc0/lc0300/Problem0305.java | 76 ------- .../leetcode/lc0/lc0300/Problem0319.java | 46 +---- .../leetcode/lc0/lc0300/Problem0329.java | 2 +- .../leetcode/lc0/lc0300/Problem0333.java | 4 +- .../leetcode/lc0/lc0300/Problem0339.java | 4 +- .../leetcode/lc0/lc0300/Problem0351.java | 2 +- .../leetcode/lc0/lc0300/Problem0366.java | 2 +- .../leetcode/lc0/lc0400/Problem0420.java | 191 +----------------- .../leetcode/lc0/lc0400/Problem0425.java | 90 --------- .../leetcode/lc0/lc0400/Problem0443.java | 19 -- .../leetcode/lc0/lc0400/Problem0449.java | 2 +- .../leetcode/lc0/lc0400/Problem0459.java | 12 -- .../leetcode/lc0/lc0400/Problem0468.java | 2 +- .../leetcode/lc0/lc0400/Problem0489.java | 2 +- .../leetcode/lc0/lc0500/Problem0502.java | 2 +- .../leetcode/lc0/lc0500/Problem0508.java | 2 +- .../leetcode/lc0/lc0500/Problem0529.java | 2 +- .../leetcode/lc0/lc0500/Problem0530.java | 4 +- .../leetcode/lc0/lc0500/Problem0545.java | 6 +- .../leetcode/lc0/lc0500/Problem0549.java | 2 +- .../leetcode/lc0/lc0500/Problem0563.java | 2 +- .../leetcode/lc0/lc0500/Problem0568.java | 2 +- .../leetcode/lc0/lc0600/Problem0634.java | 2 +- .../leetcode/lc0/lc0600/Problem0652.java | 6 +- .../leetcode/lc0/lc0600/Problem0666.java | 2 +- .../leetcode/lc0/lc0600/Problem0684.java | 2 +- .../leetcode/lc0/lc0600/Problem0694.java | 2 +- .../leetcode/lc0/lc0700/Problem0711.java | 2 +- .../leetcode/lc0/lc0700/Problem0715.java | 4 +- .../leetcode/lc0/lc0700/Problem0730.java | 2 +- .../leetcode/lc0/lc0700/Problem0736.java | 2 +- .../leetcode/lc0/lc0700/Problem0743.java | 2 +- .../leetcode/lc0/lc0700/Problem0753.java | 2 +- .../leetcode/lc0/lc0700/Problem0773.java | 2 +- .../leetcode/lc0/lc0700/Problem0779.java | 2 +- .../leetcode/lc0/lc0700/Problem0782.java | 2 +- .../leetcode/lc0/lc0800/Problem0802.java | 2 +- .../leetcode/lc0/lc0800/Problem0803.java | 2 +- .../leetcode/lc0/lc0800/Problem0813.java | 2 +- .../leetcode/lc0/lc0800/Problem0827.java | 2 +- .../leetcode/lc0/lc0800/Problem0834.java | 58 ------ .../leetcode/lc0/lc0800/Problem0842.java | 2 +- .../leetcode/lc0/lc0800/Problem0849.java | 2 +- .../leetcode/lc0/lc0800/Problem0850.java | 2 +- .../leetcode/lc0/lc0800/Problem0851.java | 2 +- .../leetcode/lc0/lc0800/Problem0878.java | 2 +- .../leetcode/lc0/lc0800/Problem0880.java | 28 --- .../leetcode/lc0/lc0800/Problem0881.java | 2 +- .../leetcode/lc0/lc0800/Problem0886.java | 2 +- .../leetcode/lc0/lc0800/Problem0887.java | 2 +- .../leetcode/lc0/lc0800/Problem0891.java | 2 +- .../leetcode/lc0/lc0900/Problem0902.java | 2 +- .../leetcode/lc0/lc0900/Problem0909.java | 2 +- .../leetcode/lc0/lc0900/Problem0913.java | 2 +- .../leetcode/lc0/lc0900/Problem0920.java | 2 +- .../leetcode/lc0/lc0900/Problem0928.java | 2 +- .../leetcode/lc0/lc0900/Problem0934.java | 2 +- .../leetcode/lc0/lc0900/Problem0940.java | 2 +- .../leetcode/lc0/lc0900/Problem0946.java | 15 -- .../leetcode/lc0/lc0900/Problem0947.java | 2 +- .../leetcode/lc0/lc0900/Problem0952.java | 2 +- .../leetcode/lc0/lc0900/Problem0958.java | 29 --- .../leetcode/lc0/lc0900/Problem0959.java | 2 +- .../leetcode/lc0/lc0900/Problem0964.java | 2 +- .../leetcode/lc0/lc0900/Problem0971.java | 2 +- .../leetcode/lc0/lc0900/Problem0975.java | 2 +- .../leetcode/lc0/lc0900/Problem0980.java | 2 +- .../leetcode/lc0/lc0900/Problem0989.java | 14 +- .../leetcode/lc0/lc0900/Problem0999.java | 2 +- .../leetcode/lc1/lc1000/Problem1007.java | 2 +- .../leetcode/lc1/lc1000/Problem1008.java | 2 +- .../leetcode/lc1/lc1000/Problem1011.java | 28 +-- .../leetcode/lc1/lc1000/Problem1012.java | 2 +- .../leetcode/lc1/lc1000/Problem1026.java | 2 +- .../leetcode/lc1/lc1000/Problem1034.java | 2 +- .../leetcode/lc1/lc1000/Problem1036.java | 2 +- .../leetcode/lc1/lc1000/Problem1039.java | 2 +- .../leetcode/lc1/lc1000/Problem1044.java | 2 +- .../leetcode/lc1/lc1000/Problem1056.java | 2 +- .../leetcode/lc1/lc1000/Problem1059.java | 2 +- .../leetcode/lc1/lc1000/Problem1066.java | 2 +- .../leetcode/lc1/lc1000/Problem1067.java | 2 +- .../leetcode/lc1/lc1000/Problem1088.java | 2 +- .../leetcode/lc1/lc1000/Problem1093.java | 2 +- .../leetcode/lc1/lc1100/Problem1101.java | 2 +- .../leetcode/lc1/lc1100/Problem1114.java | 2 +- .../leetcode/lc1/lc1100/Problem1117.java | 4 +- .../leetcode/lc1/lc1100/Problem1120.java | 2 +- .../leetcode/lc1/lc1100/Problem1135.java | 2 +- .../leetcode/lc1/lc1100/Problem1154.java | 2 +- .../leetcode/lc1/lc1100/Problem1175.java | 6 +- .../leetcode/lc1/lc1100/Problem1177.java | 2 +- .../leetcode/lc1/lc1100/Problem1192.java | 2 +- .../leetcode/lc1/lc1200/Problem1202.java | 2 +- .../leetcode/lc1/lc1200/Problem1210.java | 2 +- .../leetcode/lc1/lc1200/Problem1218.java | 19 +- .../leetcode/lc1/lc1200/Problem1223.java | 2 +- .../leetcode/lc1/lc1200/Problem1224.java | 2 +- .../leetcode/lc1/lc1200/Problem1236.java | 2 +- .../leetcode/lc1/lc1200/Problem1240.java | 2 +- .../leetcode/lc1/lc1200/Problem1245.java | 2 +- .../leetcode/lc1/lc1200/Problem1263.java | 2 +- .../leetcode/lc1/lc1200/Problem1292.java | 2 +- .../leetcode/lc1/lc1300/Problem1301.java | 2 +- .../leetcode/lc1/lc1300/Problem1312.java | 2 +- .../leetcode/lc1/lc1300/Problem1316.java | 2 +- .../leetcode/lc1/lc1300/Problem1351.java | 17 -- .../leetcode/lc1/lc1300/Problem1360.java | 2 +- .../leetcode/lc1/lc1300/Problem1366.java | 2 +- .../leetcode/lc1/lc1300/Problem1367.java | 2 +- .../leetcode/lc1/lc1300/Problem1376.java | 41 ---- .../leetcode/lc1/lc1300/Problem1383.java | 2 +- .../leetcode/lc1/lc1300/Problem1391.java | 2 +- .../leetcode/lc1/lc1400/Problem1424.java | 32 --- .../leetcode/lc1/lc1400/Problem1430.java | 2 +- .../leetcode/lc1/lc1400/Problem1431.java | 15 -- .../leetcode/lc1/lc1400/Problem1444.java | 2 +- .../leetcode/lc1/lc1400/Problem1448.java | 2 +- .../leetcode/lc1/lc1400/Problem1455.java | 2 +- .../leetcode/lc1/lc1400/Problem1464.java | 13 -- .../leetcode/lc1/lc1400/Problem1467.java | 2 +- .../leetcode/lc1/lc1400/Problem1491.java | 15 +- .../leetcode/lc1/lc1400/Problem1493.java | 37 +--- .../leetcode/lc1/lc1500/Problem1510.java | 2 +- .../leetcode/lc1/lc1500/Problem1519.java | 2 +- .../leetcode/lc1/lc1500/Problem1539.java | 38 ---- .../leetcode/lc1/lc1500/Problem1553.java | 2 +- .../leetcode/lc1/lc1500/Problem1559.java | 2 +- .../leetcode/lc1/lc1500/Problem1563.java | 2 +- .../leetcode/lc1/lc1500/Problem1568.java | 2 +- .../leetcode/lc1/lc1500/Problem1569.java | 2 +- .../leetcode/lc1/lc1500/Problem1573.java | 2 +- .../leetcode/lc1/lc1500/Problem1593.java | 2 +- .../leetcode/lc1/lc1500/Problem1594.java | 2 +- .../leetcode/lc1/lc1600/Problem1617.java | 2 +- .../leetcode/lc1/lc1600/Problem1621.java | 2 +- .../leetcode/lc1/lc1600/Problem1628.java | 4 +- .../leetcode/lc1/lc1600/Problem1631.java | 2 +- .../leetcode/lc1/lc1600/Problem1648.java | 2 +- .../leetcode/lc1/lc1600/Problem1659.java | 2 +- .../leetcode/lc1/lc1600/Problem1660.java | 2 +- .../leetcode/lc1/lc1600/Problem1675.java | 110 ---------- .../leetcode/lc1/lc1600/Problem1676.java | 2 +- .../leetcode/lc1/lc1600/Problem1682.java | 2 +- .../leetcode/lc1/lc1600/Problem1690.java | 2 +- .../leetcode/lc1/lc1700/Problem1704.java | 30 --- .../leetcode/lc1/lc1700/Problem1706.java | 2 +- .../leetcode/lc1/lc1700/Problem1711.java | 2 +- .../leetcode/lc1/lc1700/Problem1712.java | 2 +- .../leetcode/lc1/lc1700/Problem1722.java | 2 +- .../leetcode/lc1/lc1700/Problem1723.java | 2 +- .../leetcode/lc1/lc1700/Problem1730.java | 2 +- .../leetcode/lc1/lc1700/Problem1735.java | 6 +- .../leetcode/lc1/lc1700/Problem1737.java | 2 +- .../leetcode/lc1/lc1700/Problem1766.java | 2 +- .../leetcode/lc1/lc1700/Problem1774.java | 2 +- .../leetcode/lc1/lc1700/Problem1778.java | 2 +- .../leetcode/lc1/lc1700/Problem1786.java | 2 +- .../leetcode/lc1/lc1800/Problem1808.java | 2 +- .../leetcode/lc1/lc1800/Problem1810.java | 2 +- .../leetcode/lc1/lc1800/Problem1815.java | 2 +- .../leetcode/lc1/lc1800/Problem1820.java | 2 +- .../leetcode/lc1/lc1800/Problem1830.java | 4 +- .../leetcode/lc1/lc1800/Problem1849.java | 2 +- .../leetcode/lc1/lc1800/Problem1858.java | 2 +- .../leetcode/lc1/lc1800/Problem1863.java | 15 -- .../leetcode/lc1/lc1800/Problem1895.java | 2 +- .../leetcode/lc1/lc1900/Problem1905.java | 2 +- .../leetcode/lc1/lc1900/Problem1914.java | 2 +- .../leetcode/lc1/lc1900/Problem1922.java | 2 +- .../leetcode/lc1/lc1900/Problem1923.java | 2 +- .../leetcode/lc1/lc1900/Problem1931.java | 12 +- .../leetcode/lc1/lc1900/Problem1935.java | 2 +- .../leetcode/lc1/lc1900/Problem1944.java | 2 +- .../leetcode/lc1/lc1900/Problem1947.java | 2 +- .../leetcode/lc1/lc1900/Problem1958.java | 2 +- .../leetcode/lc1/lc1900/Problem1973.java | 2 +- .../leetcode/lc1/lc1900/Problem1977.java | 2 +- .../leetcode/lc1/lc1900/Problem1981.java | 2 +- .../leetcode/lc1/lc1900/Problem1998.java | 2 +- .../leetcode/lc2/lc2000/Problem2003.java | 2 +- .../leetcode/lc2/lc2000/Problem2024.java | 2 +- .../leetcode/lc2/lc2000/Problem2049.java | 2 +- .../leetcode/lc2/lc2000/Problem2052.java | 2 +- .../leetcode/lc2/lc2000/Problem2061.java | 2 +- .../leetcode/lc2/lc2000/Problem2071.java | 2 +- .../leetcode/lc2/lc2000/Problem2090.java | 23 +-- .../leetcode/lc2/lc2000/Problem2096.java | 2 +- .../leetcode/lc2/lc2100/Problem2123.java | 2 +- .../leetcode/lc2/lc2100/Problem2152.java | 2 +- .../leetcode/lc2/lc2100/Problem2157.java | 2 +- .../leetcode/lc2/lc2100/Problem2170.java | 2 +- .../leetcode/lc2/lc2100/Problem2184.java | 2 +- .../leetcode/lc2/lc2100/Problem2187.java | 4 +- .../leetcode/lc2/lc2100/Problem2189.java | 2 +- .../leetcode/lc2/lc2200/Problem2203.java | 2 +- .../leetcode/lc2/lc2200/Problem2209.java | 2 +- .../leetcode/lc2/lc2200/Problem2233.java | 2 +- .../leetcode/lc2/lc2200/Problem2244.java | 32 --- .../leetcode/lc2/lc2200/Problem2246.java | 2 +- .../leetcode/lc2/lc2200/Problem2248.java | 2 +- .../leetcode/lc2/lc2200/Problem2258.java | 2 +- .../leetcode/lc2/lc2200/Problem2266.java | 2 +- .../leetcode/lc2/lc2200/Problem2267.java | 2 +- .../leetcode/lc2/lc2300/Problem2307.java | 2 +- .../leetcode/lc2/lc2300/Problem2312.java | 2 +- .../leetcode/lc2/lc2300/Problem2322.java | 70 ------- .../leetcode/lc2/lc2300/Problem2327.java | 2 +- .../leetcode/lc2/lc2300/Problem2328.java | 2 +- .../leetcode/lc2/lc2300/Problem2338.java | 2 +- .../leetcode/lc2/lc2300/Problem2359.java | 2 +- .../leetcode/lc2/lc2300/Problem2368.java | 2 +- .../leetcode/lc2/lc2300/Problem2375.java | 2 +- .../leetcode/lc2/lc2300/Problem2378.java | 2 +- .../leetcode/lc2/lc2300/Problem2382.java | 2 +- .../leetcode/lc2/lc2300/Problem2387.java | 2 +- .../leetcode/lc2/lc2300/Problem2390.java | 58 ------ .../leetcode/lc2/lc2300/Problem2392.java | 2 +- .../leetcode/lc2/lc2400/Problem2400.java | 2 +- .../leetcode/lc2/lc2400/Problem2403.java | 2 +- .../leetcode/lc2/lc2400/Problem2405.java | 20 +- .../leetcode/lc2/lc2400/Problem2409.java | 2 +- .../leetcode/lc2/lc2400/Problem2416.java | 2 +- .../leetcode/lc2/lc2400/Problem2421.java | 2 +- .../leetcode/lc2/lc2400/Problem2431.java | 2 +- .../leetcode/lc2/lc2400/Problem2435.java | 2 +- .../leetcode/lc2/lc2400/Problem2438.java | 2 +- .../leetcode/lc2/lc2400/Problem2440.java | 2 +- .../leetcode/lc2/lc2400/Problem2445.java | 2 +- .../leetcode/lc2/lc2400/Problem2450.java | 2 +- .../leetcode/lc2/lc2400/Problem2458.java | 2 +- .../leetcode/lc2/lc2400/Problem2463.java | 2 +- .../leetcode/lc2/lc2400/Problem2464.java | 2 +- .../leetcode/lc2/lc2400/Problem2467.java | 6 +- .../leetcode/lc2/lc2400/Problem2472.java | 2 +- .../leetcode/lc2/lc2400/Problem2473.java | 2 +- .../leetcode/lc2/lc2400/Problem2476.java | 2 +- .../leetcode/lc2/lc2400/Problem2477.java | 2 +- .../leetcode/lc2/lc2400/Problem2478.java | 2 +- .../leetcode/lc2/lc2400/Problem2479.java | 6 +- .../leetcode/lc2/lc2400/Problem2484.java | 2 +- .../leetcode/lc2/lc2400/Problem2493.java | 2 +- .../leetcode/lc2/lc2500/Problem2510.java | 2 +- .../leetcode/lc2/lc2500/Problem2514.java | 2 +- .../leetcode/lc2/lc2500/Problem2518.java | 2 +- .../leetcode/lc2/lc2500/Problem2522.java | 2 +- .../leetcode/lc2/lc2500/Problem2524.java | 2 +- .../leetcode/lc2/lc2500/Problem2528.java | 2 +- .../leetcode/lc2/lc2500/Problem2538.java | 2 +- .../leetcode/lc2/lc2500/Problem2539.java | 6 +- .../leetcode/lc2/lc2500/Problem2547.java | 2 +- .../leetcode/lc2/lc2500/Problem2553.java | 19 -- .../leetcode/lc2/lc2500/Problem2556.java | 2 +- .../leetcode/lc2/lc2500/Problem2565.java | 2 +- .../leetcode/lc2/lc2500/Problem2581.java | 2 +- .../leetcode/lc2/lc2600/Problem2604.java | 2 +- .../leetcode/lc2/lc2600/Problem2608.java | 2 +- .../leetcode/lc2/lc2600/Problem2613.java | 2 +- .../leetcode/lc2/lc2600/Problem2641.java | 2 +- .../leetcode/lc2/lc2600/Problem2646.java | 2 +- .../leetcode/lc2/lc2600/Problem2658.java | 2 +- .../leetcode/lc2/lc2600/Problem2660.java | 2 +- .../leetcode/lc2/lc2600/Problem2663.java | 2 +- .../leetcode/lc2/lc2600/Problem2664.java | 2 +- .../leetcode/lc2/lc2600/Problem2673.java | 2 +- .../leetcode/lc2/lc2600/Problem2685.java | 2 +- .../leetcode/lc2/lc2600/Problem2699.java | 2 +- .../leetcode/lc2/lc2700/Problem2702.java | 2 +- .../leetcode/lc2/lc2700/Problem2719.java | 2 +- .../leetcode/lc2/lc2700/Problem2746.java | 2 +- .../leetcode/lc2/lc2700/Problem2764.java | 2 +- .../leetcode/lc2/lc2700/Problem2767.java | 2 +- .../leetcode/lc2/lc2700/Problem2770.java | 2 +- .../leetcode/lc2/lc2700/Problem2773.java | 2 +- .../leetcode/lc2/lc2700/Problem2791.java | 2 +- .../leetcode/lc2/lc2700/Problem2792.java | 2 +- .../leetcode/lc2/lc2800/Problem2801.java | 2 +- .../leetcode/lc2/lc2800/Problem2811.java | 2 +- .../leetcode/lc2/lc2800/Problem2818.java | 2 +- .../leetcode/lc2/lc2800/Problem2819.java | 2 +- .../leetcode/lc2/lc2800/Problem2827.java | 2 +- .../leetcode/lc2/lc2800/Problem2842.java | 2 +- .../leetcode/lc2/lc2800/Problem2844.java | 2 +- .../leetcode/lc2/lc2800/Problem2851.java | 2 +- .../leetcode/lc2/lc2800/Problem2852.java | 2 +- .../leetcode/lc2/lc2800/Problem2858.java | 2 +- .../leetcode/lc2/lc2800/Problem2872.java | 2 +- .../leetcode/lc2/lc2800/Problem2896.java | 2 +- .../leetcode/lc2/lc2900/Problem2902.java | 2 +- .../leetcode/lc2/lc2900/Problem2920.java | 2 +- .../leetcode/lc2/lc2900/Problem2925.java | 2 +- .../leetcode/lc2/lc2900/Problem2930.java | 2 +- .../leetcode/lc2/lc2900/Problem2934.java | 2 +- .../leetcode/lc2/lc2900/Problem2944.java | 2 +- .../leetcode/lc2/lc2900/Problem2954.java | 2 +- .../leetcode/lc2/lc2900/Problem2967.java | 2 +- .../leetcode/lc3/lc3000/Problem3003.java | 2 +- .../leetcode/lc3/lc3000/Problem3004.java | 2 +- .../leetcode/lc3/lc3000/Problem3007.java | 2 +- .../leetcode/lc3/lc3200/Problem3200.java | 22 ++ .../leetcode/lc3/lc3200/Problem3201.java | 24 +++ .../leetcode/lc3/lc3200/Problem3202.java | 24 +++ .../leetcode/lc0/lc0000/Problem0011Test.java | 2 +- .../leetcode/lc0/lc0000/Problem0020Test.java | 2 +- .../leetcode/lc0/lc0000/Problem0024Test.java | 2 +- .../leetcode/lc0/lc0000/Problem0086Test.java | 2 +- .../leetcode/lc0/lc0100/Problem0169Test.java | 2 +- .../leetcode/lc0/lc0400/Problem0420Test.java | 2 +- .../leetcode/lc0/lc0900/Problem0946Test.java | 2 +- .../leetcode/lc1/lc1000/Problem1011Test.java | 2 +- .../leetcode/lc1/lc1400/Problem1464Test.java | 2 +- .../leetcode/lc1/lc1400/Problem1491Test.java | 2 +- .../leetcode/lc2/lc2000/Problem2090Test.java | 7 +- .../leetcode/lc3/lc3200/Problem3200Test.java | 18 ++ .../leetcode/lc3/lc3200/Problem3201Test.java | 18 ++ .../leetcode/lc3/lc3200/Problem3202Test.java | 17 ++ 354 files changed, 522 insertions(+), 2175 deletions(-) delete mode 100644 src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0170.java delete mode 100644 src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0305.java delete mode 100644 src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0425.java delete mode 100644 src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0834.java delete mode 100644 src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2322.java create mode 100644 src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200.java create mode 100644 src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201.java create mode 100644 src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202.java create mode 100644 src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200Test.java create mode 100644 src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201Test.java create mode 100644 src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202Test.java diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0001.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0001.java index 3b8dc7c7..2f879bbf 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0001.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0001.java @@ -55,11 +55,11 @@ static final class IdxAndNum { num = _num; } - public int getIdx() { + int getIdx() { return idx; } - public int getNum() { + int getNum() { return num; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011.java index ace0fbd0..34250579 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011.java @@ -8,40 +8,19 @@ class Problem0011 extends LeetcodeProblem { int maxArea(final int[] _height) { - return maxAreaOptimized(_height); - } - - public int maxAreaNaive(final int[] _height) { - int minHeight = 0; - int area = 0; - int maxArea = 0; - - for (int x1 = _height.length - 1; x1 >= 0; x1--) { - for (int x2 = 0; x2 < x1; x2++) { - minHeight = Math.min(_height[x1], _height[x2]); - area = minHeight * (x1 - x2); - if (area > maxArea) { - maxArea = area; - } - } - } - return maxArea; - } - - public int maxAreaOptimized(final int[] _height) { int idxL = 0; int idxR = _height.length - 1; int hL = 0; int hR = 0; int area = 0; - int maxArea = 0; + int maxArea1 = 0; while (idxL < idxR) { hL = _height[idxL]; hR = _height[idxR]; area = Math.min(hL, hR) * (idxR - idxL); - if (area > maxArea) { - maxArea = area; + if (area > maxArea1) { + maxArea1 = area; } if (hL < hR) { @@ -54,7 +33,7 @@ public int maxAreaOptimized(final int[] _height) { } } } - return maxArea; + return maxArea1; } } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0012.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0012.java index d8619d44..b8c54fe4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0012.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0012.java @@ -2,28 +2,14 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - /** * 12. Integer to Roman. */ class Problem0012 extends LeetcodeProblem { - static final Map MAP = IntStream.range(1, 4000).boxed().collect(Collectors.toMap(k -> k, Problem0012::intToRomanSwitch)); - - public String intToRoman(final int _num) { - return intToRomanStaticMap(_num); - } - - static String intToRomanStaticMap(final int _num) { - return MAP.get(_num); - } - - static String intToRomanSwitch(final int _num) { - final int[] digits = {_num / 1000, _num / 100 % 10, _num / 10 % 10, _num % 10}; - final StringBuilder sb = new StringBuilder(); + String intToRoman(final int _num) { + int[] digits = {_num / 1000, _num / 100 % 10, _num / 10 % 10, _num % 10}; + StringBuilder sb = new StringBuilder(); for (int i = 0; i < digits.length; i++) { if (digits[i] < 1) { continue; @@ -80,57 +66,4 @@ static String intToRomanSwitch(final int _num) { return sb.toString(); } - static String intToRomanSubtraction(int _num) { - final StringBuilder sb = new StringBuilder(); - while (_num >= 1000) { - sb.append('M'); - _num -= 1000; - } - if (_num >= 900) { - sb.append("CM"); - _num -= 900; - } else if (_num >= 500) { - sb.append('D'); - _num -= 500; - } - if (_num >= 400) { - sb.append("CD"); - _num -= 400; - } else { - while (_num >= 100) { - sb.append('C'); - _num -= 100; - } - } - if (_num >= 90) { - sb.append("XC"); - _num -= 90; - } else if (_num >= 50) { - sb.append('L'); - _num -= 50; - } else if (_num >= 40) { - sb.append("XL"); - _num -= 40; - } - while (_num >= 10) { - sb.append('X'); - _num -= 10; - } - if (_num == 9) { - sb.append("IX"); - return sb.toString(); - } else if (_num == 4) { - sb.append("IV"); - return sb.toString(); - } else if (_num >= 5) { - sb.append('V'); - _num -= 5; - } - while (_num >= 1) { - sb.append('I'); - _num -= 1; - } - return sb.toString(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0015.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0015.java index 908e4efe..8292904e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0015.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0015.java @@ -9,8 +9,8 @@ */ class Problem0015 extends LeetcodeProblem { - List> threeSum2(int[] _nums) { - final int len = _nums.length; + List> threeSum(int[] _nums) { + int len = _nums.length; if (len == 0) { return List.of(); } @@ -38,34 +38,4 @@ List> threeSum2(int[] _nums) { return new ArrayList<>(set); } - public List> threeSum(int[] _nums) { - List input = Arrays.stream(_nums).sorted().boxed().toList(); - final int len = input.size(); - if (len < 3) { - return List.of(); - } - - Set> results = new HashSet<>(); - for (int first = 0; first < len - 2; first++) { - int second = first + 1; - int third = len - 1; - int sum; - while (second < third) { - sum = input.get(first) + input.get(second) + input.get(third); - if (sum == 0) { - results.add(List.of(input.get(first), input.get(second), input.get(third))); - second++; - third--; - } else if (sum < 0) { - second++; - } else { - third--; - } - } - - } - - return new ArrayList<>(results); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0017.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0017.java index ce89088a..1c8ba6de 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0017.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0017.java @@ -2,8 +2,10 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.*; -import java.util.stream.IntStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; /** * 17. Letter Combinations of a Phone @@ -11,14 +13,6 @@ */ class Problem0017 extends LeetcodeProblem { - @SuppressWarnings("unchecked") - private static final List[] DIGITS_TO_LETTERS = new List[] {null, // 0 - null, // 1 - List.of("a", "b", "c"), // 2 - List.of("d", "e", "f"), // 3 - List.of("g", "h", "i"), List.of("j", "k", "l"), List.of("m", "n", "o"), List.of("p", "q", "r", "s"), List.of("t", "u", "v"), List.of("w", "x", "y", "z") - }; - private static final char[][] DIGITS_TO_CHARS = new char[][] {null, // 0 null, // 1 {'a', 'b', 'c'}, // 2 @@ -26,7 +20,7 @@ class Problem0017 extends LeetcodeProblem { {'g', 'h', 'i'}, {'j', 'k', 'l'}, {'m', 'n', 'o'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v'}, {'w', 'x', 'y', 'z'} }; - public List letterCombinations(String _digits) { + List letterCombinations(String _digits) { if (_digits == null || _digits.isEmpty()) { return List.of(); } @@ -48,40 +42,4 @@ static Collection cartesianProduct(String _input, StringBuilder _sb, int return _product; } - public List letterCombinations2(String _digits) { - final int len = _digits.length(); - - if (len == 0) { - return List.of(); - } - - List> lol = IntStream.range(0, len) - // .map(i -> digits.charAt(i) - '0') - .map(i -> Character.getNumericValue(_digits.charAt(i))) - .mapToObj(i -> DIGITS_TO_LETTERS[i]) - .toList(); - - if (len == 1) { - return lol.get(0); - } - - Set combinations = new LinkedHashSet<>(); - - generatePermutations(lol, combinations, 0, ""); - - return new ArrayList<>(combinations); - } - - // cartesian product - void generatePermutations(List> _lists, Collection _result, int _depth, String _current) { - if (_depth == _lists.size()) { - _result.add(_current); - return; - } - - for (String element : _lists.get(_depth)) { - generatePermutations(_lists, _result, _depth + 1, _current + element); - } - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0018.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0018.java index c57c8e9d..098cf273 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0018.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0018.java @@ -2,7 +2,9 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.stream.LongStream; /** @@ -10,33 +12,7 @@ */ class Problem0018 extends LeetcodeProblem { - List> fourSum1(int[] _nums, int _target) { - final int len = _nums.length; - Arrays.sort(_nums); - - Set> sets = new HashSet<>(); - for (int i = 0; i < len - 3; i++) { - for (int j = i + 1; j < len - 2; j++) { - for (int k = j + 1; k < len - 1; k++) { - for (int p = k + 1; p < len; p++) { - int sum = _nums[i] + _nums[j] + _nums[k] + _nums[p]; - if (sum == _target) { - sets.add(List.of(_nums[i], _nums[j], _nums[k], _nums[p])); - } - } - } - } - } - - List> results = new ArrayList<>(sets); - - _nums = null; - sets = null; - - return results; - } - - public List> fourSum(int[] _nums, final int _target) { + List> fourSum(int[] _nums, final int _target) { final int len = _nums.length; if (len <= 4) { if (len == 4 && Arrays.stream(_nums).mapToLong(i -> i).sum() == _target) { @@ -88,7 +64,6 @@ public List> fourSum(int[] _nums, final int _target) { } } } - nums = null; return results; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020.java index 56b44dd2..f41b1252 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020.java @@ -28,41 +28,4 @@ boolean isValid(String _s) { return stack.isEmpty(); } - public boolean isValid2(String _s) { - if (_s.length() % 2 != 0) { - return false; - } - - final char[] charArray = _s.toCharArray(); - final char[] stack = new char[charArray.length]; - int head = 0; - for (char c : charArray) { - switch (c) { - case '{': - case '[': - case '(': - stack[head++] = c; - continue; - case '}': - if (head == 0 || stack[--head] != '{') { - return false; - } - break; - case ')': - if (head == 0 || stack[--head] != '(') { - return false; - } - break; - case ']': - if (head == 0 || stack[--head] != '[') { - return false; - } - break; - default: - break; - } - } - return head == 0; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024.java index 8f2c425c..109f875d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024.java @@ -8,7 +8,7 @@ */ class Problem0024 extends LeetcodeProblem { - static ListNode swapPairs(ListNode _head) { + ListNode swapPairs(ListNode _head) { if (_head == null || _head.next == null) { return _head; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0035.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0035.java index 0a8fb59c..03fd066c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0035.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0035.java @@ -8,10 +8,10 @@ class Problem0035 extends LeetcodeProblem { int searchInsert(int[] _nums, int _target) { - return searchInsert1(_nums, _target, 0, _nums.length - 1); + return searchInsert(_nums, _target, 0, _nums.length - 1); } - int searchInsert1(int[] _nums, int _target, int _fromIndex, int _toIndex) { + int searchInsert(int[] _nums, int _target, int _fromIndex, int _toIndex) { if (_target < _nums[_fromIndex]) { return _fromIndex; } else if (_target > _nums[_toIndex]) { @@ -34,31 +34,11 @@ int searchInsert1(int[] _nums, int _target, int _fromIndex, int _toIndex) { if (_nums[halfIndex] < _target) { // use right part of subarray - return searchInsert1(_nums, _target, halfIndex + 1, _toIndex); + return searchInsert(_nums, _target, halfIndex + 1, _toIndex); } else { // use left part of subarray - return searchInsert1(_nums, _target, _fromIndex, halfIndex == _toIndex ? halfIndex - 1 : halfIndex); + return searchInsert(_nums, _target, _fromIndex, halfIndex == _toIndex ? halfIndex - 1 : halfIndex); } } - int searchInsert2(int[] _nums, int _target) { - int start = 0; - int end = _nums.length - 1; - - while (start <= end) { - int mid = start + (end - start) / 2; - if (_nums[mid] == _target) { - return mid; - } - - if (_nums[mid] > _target) { - end = mid - 1; - } else { - start = mid + 1; - } - } - - return start; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0067.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0067.java index 297d5742..632ad6f9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0067.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0067.java @@ -10,18 +10,24 @@ class Problem0067 extends LeetcodeProblem { static final char ZERO = '0'; static final char ONE = '1'; - public String addBinary(final String _a, final String _b) { + String addBinary(String _a, String _b) { return addBinaryJdk(_a, _b); } - String addBinaryStringAdd(final String _a, final String _b) { - final int lenA = _a.length(); - final int lenB = _b.length(); - final int lenMin = Math.min(lenA, lenB); + String addBinaryJdk(String _a, String _b) { + java.math.BigInteger value1 = new java.math.BigInteger(_a, 2); + java.math.BigInteger value2 = new java.math.BigInteger(_b, 2); + return value1.add(value2).toString(2); + } + + String addBinaryStringAdd(String _a, String _b) { + int lenA = _a.length(); + int lenB = _b.length(); + int lenMin = Math.min(lenA, lenB); - final StringBuilder sbA = new StringBuilder(_a).reverse(); - final StringBuilder sbB = new StringBuilder(_b).reverse(); - final StringBuilder sbSum = new StringBuilder(); + StringBuilder sbA = new StringBuilder(_a).reverse(); + StringBuilder sbB = new StringBuilder(_b).reverse(); + StringBuilder sbSum = new StringBuilder(); char carry = ZERO; int i = 0; @@ -79,12 +85,6 @@ String addBinaryStringAdd(final String _a, final String _b) { return sbSum.reverse().toString(); } - String addBinaryJdk(final String _a, final String _b) { - java.math.BigInteger value1 = new java.math.BigInteger(_a, 2); - java.math.BigInteger value2 = new java.math.BigInteger(_b, 2); - return value1.add(value2).toString(2); - } - static java.math.BigInteger binToDec(String _str) { java.math.BigInteger dec = java.math.BigInteger.ZERO; long pow = 1L; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0070.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0070.java index 7d643062..93e9de81 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0070.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0070.java @@ -14,19 +14,4 @@ int climbStairs(int _n) { return climbStairs(_n - 2) + climbStairs(_n - 1); } - public int climbStairs2(int _n) { - if (_n == 1 || _n == 2) { - return _n; - } - - int[] ways = new int[_n]; - ways[0] = 1; - ways[1] = 2; - - for (int i = 2; i < _n; i++) { - ways[i] = ways[i - 1] + ways[i - 2]; - } - return ways[_n - 1]; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0071.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0071.java index a6591e47..e379b2ca 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0071.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0071.java @@ -14,7 +14,7 @@ class Problem0071 extends LeetcodeProblem { private static final String DOT = "."; private static final String DOTDOT = ".."; - public String simplifyPath(String _path) { + String simplifyPath(String _path) { Deque q = new ArrayDeque<>(); // iterate over string and add path to q for (String s : _path.split(SLASH)) { @@ -33,31 +33,4 @@ public String simplifyPath(String _path) { return q.isEmpty() ? SLASH : SLASH + String.join(SLASH, q.toArray(String[]::new)); } - public String simplifyPath2(String _path) { - String path = _path; - - // replace multiple consecutive by single slash - path = path.replaceAll("//+", SLASH); - - // going one level up from the root directory is a no-op - while (path.startsWith("/../")) { - path = path.substring(3); - } - - int idxRelDir = path.indexOf("/../"); - while (idxRelDir > 0) { - String leftPath = path.substring(0, idxRelDir + 1); - path = leftPath.substring(0, leftPath.lastIndexOf('/')); - idxRelDir = path.lastIndexOf("/../"); - } - - // remove trailing slash - int len = path.length(); - if (len > 1 && path.lastIndexOf('/') == len - 1) { - path = path.substring(0, len - 1); - } - - return path; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0077.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0077.java index 197350dc..9417e140 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0077.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0077.java @@ -10,12 +10,7 @@ */ class Problem0077 extends LeetcodeProblem { - /** - * @param _n Range of numbers [1, n] - * @param _k count of numbers to chose from first parameter - * @return all possible combinations - */ - public List> combine(int _n, int _k) { + List> combine(int _n, int _k) { if (_k > _n || _k < 0) { return List.of(); } else if (_k == 0) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086.java index 59a3e257..a1e89bdd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086.java @@ -8,7 +8,7 @@ */ class Problem0086 extends LeetcodeProblem { - static ListNode partition(ListNode _head, final int _x) { + ListNode partition(ListNode _head, final int _x) { final int invalidVal = -101; ListNode lessBgn = new ListNode(invalidVal); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0087.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0087.java index e5843d00..2f589e32 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0087.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0087.java @@ -2,9 +2,8 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.*; -import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.IntStream; +import java.util.HashMap; +import java.util.Map; /** * 87. Scramble String. @@ -13,7 +12,7 @@ class Problem0087 extends LeetcodeProblem { private final Map cache = new HashMap<>(); - public boolean isScramble(String _str1, String _str2) { + boolean isScramble(String _str1, String _str2) { final int len1 = _str1.length(); final int len2 = _str2.length(); @@ -45,99 +44,4 @@ && isScramble(_str1.substring(i), _str2.substring(0, len1 - i))) { return false; } - public boolean isScramble1(String _str1, String _str2) { - final int len1 = _str1.length(); - final int len2 = _str2.length(); - - if (len1 != len2) { - return false; - } else if (_str1.equals(_str2)) { - return true; - } else if (len1 == 1) { - // both size of 1 but not equal - return false; - } - - final String key = _str1 + " " + _str2; - - if (cache.containsKey(key)) { - return cache.get(key); - } - - // for every iteration two possible conditions - // 1.we should proceed without swapping - // 2.we should swap before looking next - for (int i = 1; i < len1; i++) { - // ex of without swap: gr|eat and rg|eat - boolean withoutSwap = isScramble(_str1.substring(0, i), _str2.substring(0, i)) - && - // right part of first and second string; - isScramble(_str1.substring(i), _str2.substring(i)); - - // if without swap produced a correct answer then we do not need - // to call the recursion withswap - if (withoutSwap) { - cache.put(key, true); - return true; - } - - // ex of withSwap: gr|eat rge|at - // here we compare "gr" with "at" and "eat" with "rge" - boolean withSwap = isScramble(_str1.substring(0, i), _str2.substring(len1 - i)) - && - // right part of first and left part of second - isScramble(_str1.substring(i), _str2.substring(0, len1 - i)); - - // if withSwap give us right answer then we return true - // otherwise the for loop do it work - if (withSwap) { - cache.put(key, true); - return true; - } - // we are not returning false in else case - // because we want to check further cases with the for loop - } - cache.put(key, false); - return false; - } - - public boolean isScramble2(String _str1, String _str2) { - final int len1 = _str1.length(); - final int len2 = _str2.length(); - - if (len1 != len2) { - return false; - } else if (len1 == 0) { - return true; - } else if (len1 == 1) { - return _str1.equals(_str2); - } - - if (!Arrays.equals(_str1.chars().sorted().toArray(), _str2.chars().sorted().toArray())) { - return false; - } - - Set results = new HashSet<>(); - ThreadLocalRandom rand = ThreadLocalRandom.current(); - IntStream.range(0, 100_000).forEach(i -> results.add(scramble(rand, _str1))); - return results.contains(_str2); - } - - static String scramble(ThreadLocalRandom _rand, String _str) { - final int len = _str.length(); - if (len <= 1) { - return _str; - } - int splitIdx = _rand.nextInt(0, len); - String part1 = splitIdx > 0 ? _str.substring(0, splitIdx) : ""; - String part2 = splitIdx > 0 ? _str.substring(splitIdx, len) : _str; - - boolean swap = _rand.nextBoolean(); - if (swap) { - return scramble(_rand, part2) + scramble(_rand, part1); - } else { - return scramble(_rand, part1) + scramble(_rand, part2); - } - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0099.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0099.java index 0a70f82d..27a9b9bb 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0099.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0000/Problem0099.java @@ -12,7 +12,7 @@ class Problem0099 extends LeetcodeProblem { private TreeNode second = null; private TreeNode pre = null; - public void recoverTree(TreeNode _root) { + void recoverTree(TreeNode _root) { if (_root == null) { return; } @@ -24,7 +24,7 @@ public void recoverTree(TreeNode _root) { second.val = temp; } - private void inorder(TreeNode _root) { + void inorder(TreeNode _root) { if (_root == null) { return; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0121.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0121.java index a342db75..48600a48 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0121.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0121.java @@ -3,15 +3,7 @@ import io.github.spannm.leetcode.LeetcodeProblem; /** - * 121. Best Time to Buy and Sell Stock. - *

- * Rules: - *

    - *
  • Buy before selling
  • - *
  • Single day to buy one stock
  • - *
  • Single day in the future to sell the stock
  • - *
  • If you cannot achieve any profit, return 0
  • - *
+ * 121. Best Time to Buy and Sell Stock */ class Problem0121 extends LeetcodeProblem { @@ -33,15 +25,4 @@ int maxProfit(int[] _prices) { return maxProfit; } - public int maxProfit3(int[] _prices) { - int buyPrice = Integer.MAX_VALUE; - int sellPrice = 0; - for (int i = 0; i < _prices.length / 2; i++) { - buyPrice = Math.min(buyPrice, _prices[i]); - sellPrice = Math.max(sellPrice, _prices[_prices.length - 1 - i]); - } - int profit = sellPrice - buyPrice; - return Math.max(profit, 0); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0124.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0124.java index 7897e230..0f92251f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0124.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0124.java @@ -3,27 +3,28 @@ import io.github.spannm.leetcode.LeetcodeProblem; import io.github.spannm.leetcode.dep.TreeNode; +import java.util.concurrent.atomic.AtomicInteger; + /** * 124. Binary Tree Maximum Path Sum. */ class Problem0124 extends LeetcodeProblem { - private int max = Integer.MIN_VALUE; - - public int maxPathSum(TreeNode _root) { - dfs(_root); - return max; + int maxPathSum(TreeNode _root) { + AtomicInteger max = new AtomicInteger(Integer.MIN_VALUE); + dfs(_root, max); + return max.get(); } - private int dfs(TreeNode _root) { + static int dfs(TreeNode _root, AtomicInteger _max) { if (_root == null) { return 0; } - int left = Math.max(dfs(_root.left), 0); - int right = Math.max(dfs(_root.right), 0); + int left = Math.max(dfs(_root.left, _max), 0); + int right = Math.max(dfs(_root.right, _max), 0); - max = Math.max(max, _root.val + left + right); + _max.set(Math.max(_max.get(), _root.val + left + right)); return _root.val + Math.max(left, right); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0134.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0134.java index c17d622f..2e7386b0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0134.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0134.java @@ -8,7 +8,7 @@ class Problem0134 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public int canCompleteCircuit(int[] _gas, int[] _cost) { + int canCompleteCircuit(int[] _gas, int[] _cost) { int len = _gas.length; int tank = 0; for (int g = 0; g < len; g++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0136.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0136.java index 3824e2be..7b47dcc1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0136.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0136.java @@ -2,30 +2,11 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; - /** * 136. Single Number. */ class Problem0136 extends LeetcodeProblem { - int singleNumber2(int[] _nums) { - final int len = _nums.length; - if (len == 1) { - return _nums[0]; - } - - Arrays.sort(_nums); - - for (int i = 1; i < len; i += 2) { - if (_nums[i] - _nums[i - 1] != 0) { - return _nums[i - 1]; - } - } - - return _nums[len - 1]; - } - int singleNumber(int[] _nums) { int len = _nums.length; if (len == 1) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0137.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0137.java index 82352dcf..a9b2ff36 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0137.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0137.java @@ -2,31 +2,12 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; - /** * 137. Single Number II. */ class Problem0137 extends LeetcodeProblem { - int singleNumber2(final int[] _nums) { - final int len = _nums.length; - if (len == 1) { - return _nums[0]; - } - - Arrays.sort(_nums); - - for (int i = 1; i < len; i += 3) { - if (_nums[i] - _nums[i - 1] != 0) { - return _nums[i - 1]; - } - } - - return _nums[len - 1]; - } - - public int singleNumber(final int[] _nums) { + int singleNumber(int[] _nums) { int o = 0; int t = 0; for (int num : _nums) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169.java index a8ca1b42..e8916852 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169.java @@ -9,27 +9,9 @@ */ class Problem0169 extends LeetcodeProblem { - int majorityElement1(int[] _nums) { + int majorityElement(int[] _nums) { Arrays.sort(_nums); return _nums[_nums.length / 2]; } - public int majorityElement2(int[] _nums) { - int count = 0; - int candidate = 0; - - for (int num : _nums) { - if (count == 0) { - candidate = num; - } - if (num == candidate) { - count++; - } else { - count--; - } - } - - return candidate; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0170.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0170.java deleted file mode 100644 index cd0932a6..00000000 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0170.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.spannm.leetcode.lc0.lc0100; - -import io.github.spannm.leetcode.LeetcodeProblem; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -class Problem0170 extends LeetcodeProblem { - static class TwoSum { - - private final Map map; - private final List list; - - TwoSum() { - map = new HashMap<>(); - list = new ArrayList<>(); - } - - public void add(int _number) { - list.add(_number); - map.compute(_number, (k, v) -> v == null ? 1 : v + 1); - } - - public boolean find(int _value) { - for (Integer val1 : list) { - int val2 = _value - val1; - if (map.containsKey(val2)) { - if (val1 == val2) { - if (map.get(val2) > 1) { - return true; - } - } else { - return true; - } - } - } - return false; - } - } - -} diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0179.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0179.java index 6f198351..3292dce1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0179.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0179.java @@ -3,8 +3,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; import java.util.Arrays; -import java.util.stream.Collectors; -import java.util.stream.IntStream; /** * 179. Largest Number. @@ -12,28 +10,9 @@ class Problem0179 extends LeetcodeProblem { String largestNumber(int[] _nums) { - return largestNumber2(_nums); - } - - public String largestNumber1(int[] _nums) { - String s = IntStream.of(_nums) - .mapToObj(Integer::toString) - .sorted((p1, p2) -> { - String s1 = p1 + p2; - String s2 = p2 + p1; - return s2.compareTo(s1); // reverse order here to join straight ahead later - }) - .collect(Collectors.joining("")); - if (s.charAt(0) == '0') { - return "0"; - } - return s; - } - - public String largestNumber2(int[] _nums) { - final int len = _nums.length; - if (_nums.length <= 1) { - if (_nums.length == 1) { + int len = _nums.length; + if (len <= 1) { + if (len == 1) { return Integer.toString(_nums[0]); } return ""; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0190.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0190.java index e504abaf..d2c41340 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0190.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0190.java @@ -23,10 +23,4 @@ int reverseBits(int _n) { return res; } - public int reverseBits2(int _n) { - String rev = new StringBuilder(Long.toBinaryString(_n)).reverse().toString(); - long l = Long.parseLong(rev, 2); - return (int) l; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0191.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0191.java index 1b4d05ae..bf0a1178 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0191.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0100/Problem0191.java @@ -11,16 +11,4 @@ int hammingWeight(int _n) { return Integer.toBinaryString(_n).replace("0", "").length(); } - public int hammingWeight2(int _n) { - int count = 0; - while (_n != 0) { - // check if number is odd - if ((_n & 1) == 1) { - count++; - } - _n = _n >>> 1; // unsigned right shift operator - } - return count; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0206.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0206.java index 64e793bb..8a91a03c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0206.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0206.java @@ -3,8 +3,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; import io.github.spannm.leetcode.dep.ListNode; -import java.util.Stack; - /** * 206. Reverse Linked List. */ @@ -21,27 +19,4 @@ ListNode reverseList(ListNode _head) { return prev; } - public ListNode reverseList2(ListNode _head) { - if (_head == null || _head.next == null) { - return _head; - } - - Stack stack = new Stack<>(); - ListNode node = _head; - while (node != null) { - stack.push(node); - node = node.next; - } - - ListNode reversed = stack.pop(); - node = reversed; - while (!stack.isEmpty()) { - node.next = stack.pop(); - node = node.next; - } - node.next = null; - - return reversed; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0207.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0207.java index bfb88c3d..8c933775 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0207.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0207.java @@ -13,7 +13,7 @@ class Problem0207 extends LeetcodeProblem { private static final byte VISITING = 1; private static final byte VISITED = 2; - public boolean canFinish(final int _numCourses, final int[][] _prerequisites) { + boolean canFinish(final int _numCourses, final int[][] _prerequisites) { final List> courseGraph = new ArrayList<>(_numCourses); for (int i = 0; i < _numCourses; i++) { courseGraph.add(new ArrayList<>(_numCourses)); @@ -34,7 +34,7 @@ public boolean canFinish(final int _numCourses, final int[][] _prerequisites) { return true; } - private static boolean detectCycle(final int _course, final List> _courseList, final byte[] _visitStatus) { + static boolean detectCycle(final int _course, final List> _courseList, final byte[] _visitStatus) { if (VISITING == _visitStatus[_course]) { return true; } else if (VISITED == _visitStatus[_course]) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0212.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0212.java index 98a6a18e..3a240238 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0212.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0212.java @@ -18,7 +18,7 @@ class Problem0212 extends LeetcodeProblem { private String[] words; private final Set result = new TreeSet<>(); - public List findWords(char[][] _board, String[] _words) { + List findWords(char[][] _board, String[] _words) { board = _board; words = _words; nbRows = _board.length; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0214.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0214.java index 04a82002..1384f850 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0214.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0214.java @@ -5,13 +5,12 @@ class Problem0214 extends LeetcodeProblem { String shortestPalindrome(String _s) { - String temp = _s + "#" + new StringBuilder(_s).reverse(); - int[] table = getTable(temp); + int[] table = createTable(_s + "#" + new StringBuilder(_s).reverse()); return new StringBuilder(_s.substring(table[table.length - 1])).reverse() + _s; } - public int[] getTable(String _s) { + static int[] createTable(String _s) { int[] table = new int[_s.length()]; int index = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0231.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0231.java index 52726f6a..f2b9250d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0231.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0231.java @@ -17,7 +17,7 @@ boolean isPowerOfTwo(int _n) { return _n > 0 && (_n & prev) == 0; // bitwise AND } - public boolean isPowerOfTwo2(int _n) { + boolean isPowerOfTwo2(int _n) { if (_n <= 0) { return false; } @@ -30,16 +30,9 @@ public boolean isPowerOfTwo2(int _n) { return true; } - public boolean isPowerOfTwo3(int _n) { + boolean isPowerOfTwo3(int _n) { // a power of two in binary form has and only has one "1" return _n > 0 && Integer.bitCount(_n) == 1; } - public boolean isPowerOfTwo4(int _n) { - if (_n == 0 || _n % 2 != 0) { - return false; - } - return isPowerOfTwo(_n / 2); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0239.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0239.java index 07e2fe97..a7c194a9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0239.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0239.java @@ -28,13 +28,4 @@ int[] maxSlidingWindow(int[] _nums, int _k) { return out; } - public int[] maxSlidingWindowTLE(int[] _nums, int _k) { - final int outlen = _nums.length - _k + 1; - final int[] out = new int[outlen]; - for (int i = 0; i < outlen; i++) { - out[i] = java.util.Arrays.stream(_nums, i, i + _k).max().getAsInt(); - } - return out; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0248.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0248.java index 7aebe137..654b83fe 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0248.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0248.java @@ -6,7 +6,7 @@ class Problem0248 extends LeetcodeProblem { private static final char[][] PAIRS = {{'0', '0'}, {'1', '1'}, {'6', '9'}, {'8', '8'}, {'9', '6'}}; - public int strobogrammaticInRange(String _low, String _high) { + int strobogrammaticInRange(String _low, String _high) { int[] count = {0}; for (int len = _low.length(); len <= _high.length(); len++) { char[] c = new char[len]; @@ -15,7 +15,7 @@ public int strobogrammaticInRange(String _low, String _high) { return count[0]; } - public void dfs(String _low, String _high, char[] _c, int _left, int _right, int[] _count) { + static void dfs(String _low, String _high, char[] _c, int _left, int _right, int[] _count) { if (_left > _right) { String s = new String(_c); if (s.length() == _low.length() && s.compareTo(_low) < 0 diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0271.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0271.java index 90d3b8d4..83e95742 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0271.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0271.java @@ -15,7 +15,7 @@ String encode(List _strs) { return sb.toString(); } - public List decode(String _s) { + List decode(String _s) { List result = new ArrayList<>(); int i = 0; while (i < _s.length()) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0273.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0273.java index d0887402..562717d3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0273.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0273.java @@ -9,7 +9,7 @@ class Problem0273 extends LeetcodeProblem { private static final String[] BELOW_100 = new String[] {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; private static final String[] OVER_1000 = new String[] {"Thousand", "Million", "Billion"}; - public String numberToWords(int _num) { + String numberToWords(int _num) { if (_num < 10) { return BELOW_10[_num]; } @@ -28,7 +28,7 @@ public String numberToWords(int _num) { return result.trim(); } - private String hundredHelper(int _num) { + static String hundredHelper(int _num) { String nstr = ""; if (_num >= 100) { nstr = BELOW_10[_num / 100] + " Hundred "; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0278.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0278.java index 7b198bb8..bb00f5bd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0278.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0278.java @@ -9,12 +9,12 @@ public abstract class Problem0278 extends LeetcodeProblem { abstract boolean isBadVersionImpl(int _version); - public boolean isBadVersion(int _version) { + boolean isBadVersion(int _version) { boolean bad = isBadVersionImpl(_version); return bad; } - public int firstBadVersion(int _nbVersions) { + int firstBadVersion(int _nbVersions) { int fromVersion = 1; int toVersion = _nbVersions; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0286.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0286.java index 6e6dece7..1b451d26 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0286.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0286.java @@ -6,7 +6,7 @@ class Problem0286 extends LeetcodeProblem { private static final int[] DIRS = new int[] {0, 1, 0, -1, 0}; - public void wallsAndGates(int[][] _rooms) { + void wallsAndGates(int[][] _rooms) { if (_rooms == null || _rooms.length == 0 || _rooms[0].length == 0) { return; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0298.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0298.java index 16423837..49a504d4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0298.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0200/Problem0298.java @@ -7,7 +7,7 @@ class Problem0298 extends LeetcodeProblem { private int max = 1; - public int longestConsecutive(TreeNode _root) { + int longestConsecutive(TreeNode _root) { if (_root == null) { return 0; } @@ -15,7 +15,7 @@ public int longestConsecutive(TreeNode _root) { return max; } - private void dfs(TreeNode _root, int _curr, int _target) { + void dfs(TreeNode _root, int _curr, int _target) { if (_root == null) { return; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0305.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0305.java deleted file mode 100644 index e5bc4be1..00000000 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0305.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.github.spannm.leetcode.lc0.lc0300; - -import io.github.spannm.leetcode.LeetcodeProblem; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -class Problem0305 extends LeetcodeProblem { - - int find(int[] _father, int _id) { - int tf = _father[_id]; - while (tf != _father[tf]) { - tf = _father[tf]; - } - int cur = _id; - int tmp; - while (_father[cur] != tf) { - tmp = _father[cur]; - _father[cur] = tf; - cur = tmp; - } - return tf; - } - - public void union(int[] _father, int[] _sz, int _id1, int _id2) { - int tf1 = find(_father, _id1); - int tf2 = find(_father, _id2); - if (tf1 != tf2) { - if (_sz[tf1] > _sz[tf2]) { - _father[tf2] = tf1; - _sz[tf1] += _sz[tf2]; - } else { - _father[tf1] = tf2; - _sz[tf2] += _sz[tf1]; - } - } - } - - public List numIslands2(int _m, int _n, int[][] _positions) { - if (_m == 0 || _n == 0) { - return List.of(); - } - List res = new ArrayList<>(); - int[] father = new int[_m * _n]; - Arrays.fill(father, -1); - int[] sz = new int[_m * _n]; - int[] dr = {0, 0, -1, 1}; - int[] dc = {-1, 1, 0, 0}; - int r; - int c; - int nr; - int nc; - int count = 0; - for (int[] position : _positions) { - r = position[0]; - c = position[1]; - count++; - father[r * _n + c] = r * _n + c; - sz[r * _n + c] = 1; - for (int j = 0; j < 4; j++) { - nr = r + dr[j]; - nc = c + dc[j]; - if (nr >= 0 && nr < _m && nc >= 0 && nc < _n && father[nr * _n + nc] != -1) { - if (find(father, r * _n + c) != find(father, nr * _n + nc)) { - count--; - union(father, sz, r * _n + c, nr * _n + nc); - } - } - } - res.add(count); - } - return res; - } - -} diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0319.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0319.java index b7f51b98..cbae8289 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0319.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0319.java @@ -2,57 +2,13 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; - /** * 319. Bulb Switcher. */ class Problem0319 extends LeetcodeProblem { - static final int ON = 1; - static final int OFF = -1; - - public int bulbSwitch(final int _nbBulbs) { + int bulbSwitch(final int _nbBulbs) { return (int) Math.sqrt(_nbBulbs); } - public int bulbSwitchNaive(final int _nbBulbs) { - if (_nbBulbs <= 1) { - return _nbBulbs; - } else if (_nbBulbs == 2) { - return 1; - } - - final int nbRounds = _nbBulbs; - - int[] bulbs = new int[_nbBulbs]; - - // round 1: turn on all bulbs - Arrays.fill(bulbs, ON); - - // round 2: turn off every 2nd bulb - for (int idx = 2 - 1; idx < _nbBulbs; idx += 2) { - bulbs[idx] = OFF; - } - - // round 3 .. nbBulbs - 1: toggle every nth bulb - for (int round = 3; round < nbRounds; round++) { - for (int idx = round - 1; idx < _nbBulbs; idx += round) { - bulbs[idx] *= -1; // toggle - } - } - - // last round: toggle last bulb - bulbs[_nbBulbs - 1] *= -1; - - int nbOn = 0; - for (int idx = 0; idx < _nbBulbs; idx++) { - if (bulbs[idx] == ON) { - nbOn++; - } - } - - return nbOn; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0329.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0329.java index 41c2b5ba..435e7b3f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0329.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0329.java @@ -6,7 +6,7 @@ class Problem0329 extends LeetcodeProblem { private static final int[] DIRS = new int[] {0, 1, 0, -1, 0}; - public int longestIncreasingPath(int[][] _matrix) { + int longestIncreasingPath(int[][] _matrix) { int nbRows = _matrix.length; int nbCols = _matrix[0].length; int max = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0333.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0333.java index c96db2be..18aacb3a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0333.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0333.java @@ -6,7 +6,7 @@ class Problem0333 extends LeetcodeProblem { private int max = 0; - public int largestBSTSubtree(TreeNode _root) { + int largestBSTSubtree(TreeNode _root) { if (_root == null) { return 0; } @@ -14,7 +14,7 @@ public int largestBSTSubtree(TreeNode _root) { return max; } - private Result traverse(TreeNode _root) { + Result traverse(TreeNode _root) { if (_root == null) { return new Result(0, Integer.MAX_VALUE, Integer.MIN_VALUE); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0339.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0339.java index f35c92b6..0072ecb8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0339.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0339.java @@ -8,11 +8,11 @@ class Problem0339 extends LeetcodeProblem { private int sum = 0; - public int depthSum(List _nestedList) { + int depthSum(List _nestedList) { return dfs(_nestedList, 1); } - private int dfs(List _nestedList, int _depth) { + int dfs(List _nestedList, int _depth) { for (NestedInteger ni : _nestedList) { if (ni.isInteger()) { sum += _depth * ni.getInteger(); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0351.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0351.java index b0fe3c5f..8544c389 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0351.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0351.java @@ -7,7 +7,7 @@ class Problem0351 extends LeetcodeProblem { private int[][] jumps; private boolean[] visited; - public int numberOfPatterns(int _m, int _n) { + int numberOfPatterns(int _m, int _n) { jumps = new int[10][10]; jumps[1][3] = jumps[3][1] = 2; jumps[4][6] = jumps[6][4] = 5; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0366.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0366.java index 651edf06..d0e051b3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0366.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0300/Problem0366.java @@ -10,7 +10,7 @@ class Problem0366 extends LeetcodeProblem { private final List> result = new ArrayList<>(); - public List> findLeaves(TreeNode _root) { + List> findLeaves(TreeNode _root) { dfs(_root); return result; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420.java index 8e72a0c1..ed86d63b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420.java @@ -2,201 +2,12 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.stream.IntStream; - /** * 420. Strong Password Checker. */ class Problem0420 extends LeetcodeProblem { - private static final int MIN_LEN = 6; - private static final int MAX_LEN = 20; - private static final int MIN_DIGIT = 1; - private static final int MIN_LC = 1; - private static final int MIN_UC = 1; - - private final java.util.regex.Pattern pattCharsInRow = java.util.regex.Pattern.compile("(.)(\\1{2})"); - - public int strongPasswordChecker1(String _password) { - int len = checkArgs(_password); - - // CASE 1 - // character count is between 6 and 20. All we need to do is figure out how many edits we need - if (len >= MIN_LEN && len <= MAX_LEN) { - int nbEditsForCharGroups = calcEditsForCharGroups(_password); - - int nbEditsForSequences = 0; - java.util.regex.Matcher m = java.util.regex.Pattern.compile("(.)(\\1{2,})").matcher(_password); - while (m.find()) { - nbEditsForSequences += (m.group(2).length() + 1) / 3; - } - return IntStream.of(nbEditsForCharGroups, nbEditsForSequences).max().orElse(0); - } - - // CASE 2 - // character count is less than 6 - if (len < MIN_LEN) { - int nbAddsForLen = MIN_LEN - len; - int nbEditsForCharGroups = calcEditsForCharGroups(_password); - int nbEditsForSequences = 0; - java.util.regex.Matcher m = java.util.regex.Pattern.compile("(.)(\\1{2,})").matcher(_password); - while (m.find()) { - nbEditsForSequences += (m.group(2).length() + 1) / 2 - 1; - } - return IntStream.of(nbAddsForLen, nbEditsForCharGroups, nbEditsForSequences).max().orElse(0); - } - - // CASE 3 - // In this case, we need to remove a certain amount of characters (until password length is down to 20) to - // satisfy Constraint A. Unfortunately Constraint A and Constraint B are completely independent (one - // requires explicit removes, the other requires edits), but they both have independent two-birds-one-stone - // relationships with Constraint C (for which both edits and removes are potential solutions). This makes - // Constraint C very complicated to accurately calculate. We'll get to this below. - if (len > MAX_LEN) { - int nbDelsForLen = len - MAX_LEN; - int nbEditsForCharGroups = calcEditsForCharGroups(_password); - - int nbRemovesForSequences = 0; - java.util.regex.Pattern p = java.util.regex.Pattern.compile("(.)(\\1{2,})"); - java.util.regex.Matcher m = p.matcher(_password); - while (m.find() && len > MAX_LEN) { - int seqLen = m.group(2).length() + 1; - int idxEnd = m.end(); - if ((seqLen - 2) % 3 == 1) { - _password = new StringBuilder(_password).deleteCharAt(idxEnd - 1).toString(); - nbRemovesForSequences += 1; - } else if ((seqLen - 2) % 3 == 2) { - _password = new StringBuilder(_password).deleteCharAt(idxEnd - 1).deleteCharAt(idxEnd - 2).toString(); - nbRemovesForSequences += 2; - } else if ((seqLen - 2) % 3 == 0) { - _password = new StringBuilder(_password) - .deleteCharAt(idxEnd - 1) - .deleteCharAt(idxEnd - 2) - .deleteCharAt(idxEnd - 3) - .toString(); - nbRemovesForSequences += 3; - } - len = _password.length(); - if (len < MAX_LEN) { - nbRemovesForSequences -= MAX_LEN - len; - break; - } - m = p.matcher(_password); - } - - return nbDelsForLen + Math.max(nbEditsForCharGroups, nbRemovesForSequences); - } - - return 0; - } - - int checkArgs(String _password) { - int len = java.util.Optional.ofNullable(_password).map(String::length).orElse(0); - if (len < 1 || len > 50) { - throw new IllegalArgumentException("Invalid input: " + _password); - } - return len; - } - - int calcEditsForCharGroups(String _password) { - int nbDigits = 0; - int nbLc = 0; - int nbUc = 0; - - for (int i = 0; i < _password.length(); i++) { - char c = _password.charAt(i); - if (Character.isDigit(c)) { - nbDigits++; - } else if (Character.isLowerCase(c)) { - nbLc++; - } else if (Character.isUpperCase(c)) { - nbUc++; - } - } - - return IntStream.of(MIN_DIGIT - nbDigits, MIN_LC - nbLc, MIN_UC - nbUc) - .filter(i -> i > 0).sum(); - } - - public int strongPasswordChecker2(String _password) { - int len = checkArgs(_password); - - int nbDigits = 0; - int nbLc = 0; - int nbUc = 0; - - int changeSteps = 0; - if (len < MIN_LEN) { - changeSteps += MIN_LEN - len; - return changeSteps; - } else if (len > MAX_LEN) { - // if too long, reduce repetitions - changeSteps += len - MAX_LEN; - - java.util.regex.Matcher m = pattCharsInRow.matcher(_password); - while (m.find() && len > MAX_LEN) { - _password = new StringBuilder(_password).deleteCharAt(m.end()).toString(); - len = _password.length(); - m = pattCharsInRow.matcher(_password); - } - - } - - for (int i = 0; i < len; i++) { - char c = _password.charAt(i); - if (Character.isDigit(c)) { - nbDigits++; - } else if (Character.isLowerCase(c)) { - nbLc++; - } else if (Character.isUpperCase(c)) { - nbUc++; - } - } - if (nbDigits < MIN_DIGIT) { - changeSteps += MIN_DIGIT - nbDigits; - } - if (nbLc < MIN_LC) { - changeSteps += MIN_LC - nbLc; - } - if (nbUc < MIN_UC) { - changeSteps += MIN_UC - nbUc; - } - java.util.regex.Matcher m = pattCharsInRow.matcher(_password); - while (m.find()) { - char repeatChar = m.group(1).charAt(0); - // a change of repeated chars can be broken up by insert a char from a missing character group - if (nbDigits == 0 || nbLc == 0 || nbUc == 0) { - if (Character.isDigit(repeatChar)) { - // replace digit by lc/uc char - if (nbLc == 0) { - nbLc++; - } else if (nbUc == 0) { - nbUc++; - } - } else if (Character.isLowerCase(repeatChar)) { - // replace lc by digit/uc char - if (nbDigits == 0) { - nbDigits++; - } else if (nbUc == 0) { - nbUc++; - } - } else if (Character.isUpperCase(repeatChar)) { - // replace lc by digit/uc char - if (nbDigits == 0) { - nbDigits++; - } else if (nbLc == 0) { - nbLc++; - } - } - } else { - changeSteps++; - } - } - - return changeSteps; - } - - public int strongPasswordChecker3(String _password) { + int strongPasswordChecker(String _password) { final char[] carr = _password.toCharArray(); final int len = carr.length; final int[] arr = new int[len]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0425.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0425.java deleted file mode 100644 index aff06e85..00000000 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0425.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.github.spannm.leetcode.lc0.lc0400; - -import io.github.spannm.leetcode.LeetcodeProblem; - -import java.util.ArrayList; -import java.util.List; - -class Problem0425 extends LeetcodeProblem { - - static class TrieNode { - private final List startWith; - private final TrieNode[] children; - - TrieNode() { - startWith = new ArrayList<>(); - children = new TrieNode[26]; - } - } - - static class Trie { - private final TrieNode root; - - Trie(String[] _words) { - root = new TrieNode(); - for (String word : _words) { - TrieNode cur = root; - for (char ch : word.toCharArray()) { - int index = ch - 'a'; - if (cur.children[index] == null) { - cur.children[index] = new TrieNode(); - } - cur.children[index].startWith.add(word); - cur = cur.children[index]; - } - } - } - - List findByPrefix(String _prefix) { - List ans = new ArrayList<>(); - TrieNode cur = root; - for (char ch : _prefix.toCharArray()) { - int index = ch - 'a'; - if (cur.children[index] == null) { - return ans; - } - - cur = cur.children[index]; - } - ans.addAll(cur.startWith); - return ans; - } - } - - public List> wordSquares(String[] _words) { - List> ans = new ArrayList<>(); - if (_words == null || _words.length == 0) { - return ans; - } - int len = _words[0].length(); - Trie trie = new Trie(_words); - List ansBuilder = new ArrayList<>(); - for (String w : _words) { - ansBuilder.add(w); - search(len, trie, ans, ansBuilder); - ansBuilder.remove(ansBuilder.size() - 1); - } - - return ans; - } - - private void search(int _len, Trie _trie, List> _ans, List _ansBuilder) { - if (_ansBuilder.size() == _len) { - _ans.add(new ArrayList<>(_ansBuilder)); - return; - } - - int idx = _ansBuilder.size(); - StringBuilder sb = new StringBuilder(); - for (String s : _ansBuilder) { - sb.append(s.charAt(idx)); - } - List startWith = _trie.findByPrefix(sb.toString()); - for (String sw : startWith) { - _ansBuilder.add(sw); - search(_len, _trie, _ans, _ansBuilder); - _ansBuilder.remove(_ansBuilder.size() - 1); - } - } - -} diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0443.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0443.java index e793bdf5..a7e7433e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0443.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0443.java @@ -53,23 +53,4 @@ int compress(char[] _chars) { return idxOutput; } - public int compress2(char[] _chars) { - int len = _chars.length; - int k = 0; // out index - for (int i = 0, j = i + 1; i < len;) { - while (j < len && _chars[j] == _chars[i]) { - j++; - } - _chars[k++] = _chars[i]; - if (j - i > 1) { - String count = String.valueOf(j - i); - for (char c : count.toCharArray()) { - _chars[k++] = c; - } - } - i = j; - } - return k; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0449.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0449.java index d778f0cd..817fdf6d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0449.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0449.java @@ -19,7 +19,7 @@ private static String serialize(TreeNode _root, StringBuilder _sb) { return _sb.toString(); } - public TreeNode deserialize(String _data) { + TreeNode deserialize(String _data) { if (_data == null || _data.isEmpty()) { return null; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0459.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0459.java index 3e56a94f..dcef7ab5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0459.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0459.java @@ -26,16 +26,4 @@ boolean repeatedSubstringPattern(String _s) { return false; } - public boolean repeatedSubstringPattern2(String _s) { - final int len = _s.length(); - if (len <= 1) { - return false; - } - - // capture group and backreferences - java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("^([a-z]{1," + len / 2 + "}?)\\1+$"); - java.util.regex.Matcher matcher = pattern.matcher(_s); - return matcher.matches(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0468.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0468.java index aa4e20a7..9482f567 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0468.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0468.java @@ -16,7 +16,7 @@ class Problem0468 extends LeetcodeProblem { private static final String IPV4 = "IPv4"; private static final String IPV6 = "IPv6"; - public String validIPAddress(String _queryIP) { + String validIPAddress(String _queryIP) { if (_queryIP == null || _queryIP.length() < 7) { return NEITHER; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0489.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0489.java index 9e07b17c..35d66c4d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0489.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0400/Problem0489.java @@ -14,7 +14,7 @@ class Problem0489 extends LeetcodeProblem { private static final int[] DIRS = {-1, 0, 1, 0, -1}; - public void cleanRoom(Robot _robot) { + void cleanRoom(Robot _robot) { dfs(0, 0, 0, _robot, new HashSet<>()); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0502.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0502.java index f4df375b..4fadf447 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0502.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0502.java @@ -40,7 +40,7 @@ int findMaximizedCapitalImpl(int _maxProjects, int _initialCapital, int[] _arrPr return availCapital; } - public static final class Project { + static final class Project { private final int reqCapital; private final int profit; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0508.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0508.java index 0403443b..22dc7e93 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0508.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0508.java @@ -14,7 +14,7 @@ class Problem0508 extends LeetcodeProblem { private Map counter; private int max; - public int[] findFrequentTreeSum(TreeNode _root) { + int[] findFrequentTreeSum(TreeNode _root) { counter = new HashMap<>(); max = Integer.MIN_VALUE; dfs(_root); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0529.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0529.java index 7556d878..5e13c124 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0529.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0529.java @@ -11,7 +11,7 @@ class Problem0529 extends LeetcodeProblem { private int nbRows; private int nbCols; - public char[][] updateBoard(char[][] _board, int[] _click) { + char[][] updateBoard(char[][] _board, int[] _click) { nbRows = _board.length; nbCols = _board[0].length; board = _board; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0530.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0530.java index bd72325a..fb12a170 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0530.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0530.java @@ -12,7 +12,7 @@ class Problem0530 extends LeetcodeProblem { private int min = Integer.MAX_VALUE; private Integer prev = null; - public int getMinimumDifference(TreeNode _node) { + int getMinimumDifference(TreeNode _node) { if (_node == null) { return min; } @@ -29,7 +29,7 @@ public int getMinimumDifference(TreeNode _node) { return min; } - public int getMinimumDifference2(TreeNode _root) { + int getMinimumDifference2(TreeNode _root) { return inorderTraversal(_root, Integer.MAX_VALUE); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0545.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0545.java index b5d3a1c7..031846a3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0545.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0545.java @@ -23,7 +23,7 @@ List boundaryOfBinaryTree(TreeNode _root) { return nodes; } - public void leftBoundary(TreeNode _root, List _nodes) { + void leftBoundary(TreeNode _root, List _nodes) { if (_root == null || _root.left == null && _root.right == null) { return; } @@ -35,7 +35,7 @@ public void leftBoundary(TreeNode _root, List _nodes) { } } - public void rightBoundary(TreeNode _root, List _nodes) { + void rightBoundary(TreeNode _root, List _nodes) { if (_root == null || _root.right == null && _root.left == null) { return; } @@ -43,7 +43,7 @@ public void rightBoundary(TreeNode _root, List _nodes) { _nodes.add(_root.val); } - public void addLeaves(TreeNode _root, List _nodes) { + void addLeaves(TreeNode _root, List _nodes) { if (_root == null) { return; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0549.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0549.java index e96de057..2d58c948 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0549.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0549.java @@ -7,7 +7,7 @@ class Problem0549 extends LeetcodeProblem { private int max = 0; - public int longestConsecutive(TreeNode _root) { + int longestConsecutive(TreeNode _root) { longestPath(_root); return max; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0563.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0563.java index 7eaf3466..abc43021 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0563.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0563.java @@ -7,7 +7,7 @@ class Problem0563 extends LeetcodeProblem { private int tilt = 0; - public int findTilt(TreeNode _root) { + int findTilt(TreeNode _root) { findTiltDfs(_root); return tilt; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0568.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0568.java index 99bcf7f8..68ac8f29 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0568.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0500/Problem0568.java @@ -14,7 +14,7 @@ int maxVacationDays(int[][] _flights, int[][] _days) { return dfs(_flights, _days, 0, 0, memo); } - public int dfs(int[][] _flights, int[][] _days, int _curCity, int _weekno, int[][] _memo) { + int dfs(int[][] _flights, int[][] _days, int _curCity, int _weekno, int[][] _memo) { if (_weekno == _days[0].length) { return 0; } else if (_memo[_curCity][_weekno] != Integer.MIN_VALUE) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0634.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0634.java index fd854168..caafed46 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0634.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0634.java @@ -5,7 +5,7 @@ class Problem0634 extends LeetcodeProblem { private static final int M = 1000000007; - public int findDerangement(int _n) { + int findDerangement(int _n) { long ans = 1; for (int i = 1; i <= _n; i++) { ans = (i * ans % M + (i % 2 == 0 ? 1 : -1)) % M; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0652.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0652.java index 2fa4680c..21287a66 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0652.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0652.java @@ -19,7 +19,7 @@ List findDuplicateSubtrees(TreeNode _root) { return dups; } - private String countDups(TreeNode _root, Map _count, List _dups) { + static String countDups(TreeNode _root, Map _count, List _dups) { if (_root == null) { return ""; } @@ -36,7 +36,7 @@ private String countDups(TreeNode _root, Map _count, List findDuplicateSubtrees2(TreeNode _root) { + List findDuplicateSubtrees2(TreeNode _root) { Map> map = new HashMap<>(); collectSubTreesByValString(map, _root); return map.values().stream() @@ -51,7 +51,7 @@ public List findDuplicateSubtrees2(TreeNode _root) { * @param _map Map to collect into * @param _root the root of the tree */ - private void collectSubTreesByValString(final Map> _map, TreeNode _root) { + static void collectSubTreesByValString(final Map> _map, TreeNode _root) { if (_root == null) { return; } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0666.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0666.java index ed771c95..f902b203 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0666.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0666.java @@ -6,7 +6,7 @@ class Problem0666 extends LeetcodeProblem { private int totalSum = 0; - public int pathSum(int[] _nums) { + int pathSum(int[] _nums) { TreeNode root = constructTree(_nums); if (root == null) { return 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0684.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0684.java index 02d9a733..f5502e1a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0684.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0684.java @@ -67,7 +67,7 @@ private boolean isTree() { } } - public int[] findRedundantConnection(int[][] _edges) { + int[] findRedundantConnection(int[][] _edges) { UnionFind unionFind = new UnionFind(_edges); int[] result = new int[] {}; for (int[] edge : _edges) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0694.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0694.java index a199faed..319103bc 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0694.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0600/Problem0694.java @@ -10,7 +10,7 @@ class Problem0694 extends LeetcodeProblem { private static final int[][] DIRS = new int[][] {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; - public int numDistinctIslands(int[][] _grid) { + int numDistinctIslands(int[][] _grid) { int nbRows = _grid.length; int nbCols = _grid[0].length; Set>> uqShapeIslands = new HashSet<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0711.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0711.java index 8cfd9b11..a9158f92 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0711.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0711.java @@ -13,7 +13,7 @@ class Problem0711 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int numDistinctIslands2(int[][] _grid) { + int numDistinctIslands2(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0715.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0715.java index efbfe28f..c98dcb5c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0715.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0715.java @@ -21,14 +21,14 @@ public void removeRange(int left, int right) { } - public static class Node { + static class Node { private Node left; private Node right; private int add; private boolean v; } - public static class SegmentTree { + static class SegmentTree { private final Node root = new Node(); public void modify(int _left, int _right, int _v) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0730.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0730.java index b95eb514..fd2fedbc 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0730.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0730.java @@ -9,7 +9,7 @@ class Problem0730 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int countPalindromicSubsequences(String _s) { + int countPalindromicSubsequences(String _s) { int len = _s.length(); long[][][] dp = new long[len][len][4]; for (int i = 0; i < len; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0736.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0736.java index c0a04b8c..ddb73952 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0736.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0736.java @@ -13,7 +13,7 @@ class Problem0736 extends LeetcodeProblem { private String expr; private final Map> scope = new HashMap<>(); - public int evaluate(String _expr) { + int evaluate(String _expr) { expr = _expr; return eval(); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0743.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0743.java index fbc89bf7..ff6df744 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0743.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0743.java @@ -38,7 +38,7 @@ private int findMinUnvisitedIndex(int[] _a, boolean[] _visited) { return minIdx; } - public int networkDelayTime(int[][] _times, int _n, int _k) { + int networkDelayTime(int[][] _times, int _n, int _k) { int[][] weights = parseTimes(_times, _n); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0753.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0753.java index 1f7f1f5f..777082cd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0753.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0753.java @@ -14,7 +14,7 @@ class Problem0753 extends LeetcodeProblem { private final StringBuilder ans = new StringBuilder(); private int mod; - public String crackSafe(int _n, int _k) { + String crackSafe(int _n, int _k) { mod = (int) Math.pow(10, _n - 1); dfs(0, _k); ans.append("0".repeat(_n - 1)); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0773.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0773.java index d450978e..06eae45c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0773.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0773.java @@ -13,7 +13,7 @@ class Problem0773 extends LeetcodeProblem { private final int m = 2; private final int n = 3; - public int slidingPuzzle(int[][] _board) { + int slidingPuzzle(int[][] _board) { String start = ""; String end = "123450"; String seq = ""; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0779.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0779.java index 760dbce6..276294d0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0779.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0779.java @@ -21,7 +21,7 @@ static int kthGrammar(int _n, int _k) { } } - public int kthGrammar2(int _n, int _k) { + int kthGrammar2(int _n, int _k) { List> lists = new ArrayList<>(); lists.add(List.of(0)); for (int i = 1; i <= _n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0782.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0782.java index be63ffb1..5172ea65 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0782.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0700/Problem0782.java @@ -9,7 +9,7 @@ class Problem0782 extends LeetcodeProblem { private int len; - public int movesToChessboard(int[][] _board) { + int movesToChessboard(int[][] _board) { len = _board.length; int mask = (1 << len) - 1; int rowMask = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0802.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0802.java index 6bd29b58..04a08b3f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0802.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0802.java @@ -14,7 +14,7 @@ class Problem0802 extends LeetcodeProblem { private static final byte UNSAFE = 1; private static final byte SAFE = -1; - public static List eventualSafeNodes(final int[][] _graph) { + static List eventualSafeNodes(final int[][] _graph) { final byte[] states = new byte[_graph.length]; // contains UNKNOWN (0) by default return IntStream.range(0, _graph.length) diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0803.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0803.java index d9fcd18e..9679a267 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0803.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0803.java @@ -10,7 +10,7 @@ class Problem0803 extends LeetcodeProblem { private int[] p; private int[] size; - public int[] hitBricks(int[][] _grid, int[][] _hits) { + int[] hitBricks(int[][] _grid, int[][] _hits) { int nbRows = _grid.length; int nbCols = _grid[0].length; p = new int[nbRows * nbCols + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0813.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0813.java index d7a63116..da0c8b57 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0813.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0813.java @@ -11,7 +11,7 @@ class Problem0813 extends LeetcodeProblem { private int[] s; private int n; - public double largestSumOfAverages(int[] _nums, int _k) { + double largestSumOfAverages(int[] _nums, int _k) { n = _nums.length; s = new int[n + 1]; f = new Double[n + 1][_k + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0827.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0827.java index 042daf69..1003bcd7 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0827.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0827.java @@ -15,7 +15,7 @@ class Problem0827 extends LeetcodeProblem { private int[] p; private int ans = 1; - public int largestIsland(int[][] _grid) { + int largestIsland(int[][] _grid) { int n = _grid.length; p = new int[n * n]; int[] size = new int[n * n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0834.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0834.java deleted file mode 100644 index 5d55dcc3..00000000 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0834.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.github.spannm.leetcode.lc0.lc0800; - -import io.github.spannm.leetcode.LeetcodeProblem; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 834. Sum of Distances in Tree. - */ -class Problem0834 extends LeetcodeProblem { - - private int n; - private int[] ans; - private int[] size; - private List[] g; - - int[] sumOfDistancesInTree(int _n, int[][] _edges) { - n = _n; - @SuppressWarnings("unchecked") - List[] lists = new List[_n]; - g = lists; - ans = new int[_n]; - size = new int[_n]; - Arrays.setAll(g, k -> new ArrayList<>()); - for (var e : _edges) { - int a = e[0]; - int b = e[1]; - g[a].add(b); - g[b].add(a); - } - dfs1(0, -1, 0); - dfs2(0, -1, ans[0]); - return ans; - } - - void dfs1(int _i, int _fa, int _d) { - ans[0] += _d; - size[_i] = 1; - for (int j : g[_i]) { - if (j != _fa) { - dfs1(j, _i, _d + 1); - size[_i] += size[j]; - } - } - } - - void dfs2(int _i, int _fa, int _t) { - ans[_i] = _t; - for (int j : g[_i]) { - if (j != _fa) { - dfs2(j, _i, _t - size[j] + n - size[j]); - } - } - } - -} diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0842.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0842.java index c942f06d..c16831d2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0842.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0842.java @@ -13,7 +13,7 @@ class Problem0842 extends LeetcodeProblem { private final List ans = new ArrayList<>(); private String num; - public List splitIntoFibonacci(String _num) { + List splitIntoFibonacci(String _num) { num = _num; dfs(0); return ans; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0849.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0849.java index dafb12c6..d78b00cf 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0849.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0849.java @@ -5,7 +5,7 @@ class Problem0849 extends LeetcodeProblem { private int maxDist = 0; - public int maxDistToClosest(int[] _seats) { + int maxDistToClosest(int[] _seats) { for (int i = 0; i < _seats.length; i++) { if (_seats[i] == 0) { extend(_seats, i); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0850.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0850.java index e5e37e6d..f5aaae67 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0850.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0850.java @@ -11,7 +11,7 @@ class Problem0850 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int rectangleArea(int[][] _rectangles) { + int rectangleArea(int[][] _rectangles) { int n = _rectangles.length; int[][] segs = new int[n << 1][4]; int i = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0851.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0851.java index 5258fa87..612f571c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0851.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0851.java @@ -15,7 +15,7 @@ class Problem0851 extends LeetcodeProblem { private int[] quiet; private int[] ans; - public int[] loudAndRich(int[][] _richer, int[] _quiet) { + int[] loudAndRich(int[][] _richer, int[] _quiet) { int n = _quiet.length; quiet = _quiet; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0878.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0878.java index 164acc9a..e6bfb922 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0878.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0878.java @@ -9,7 +9,7 @@ class Problem0878 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int nthMagicalNumber(int _n, int _a, int _b) { + int nthMagicalNumber(int _n, int _a, int _b) { int c = _a * _b / gcd(_a, _b); long l = 0; long r = (long) (_a + _b) * _n; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0880.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0880.java index 18f4822e..b349be51 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0880.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0880.java @@ -41,32 +41,4 @@ String decodeAtIndex(String _s, int _k) { return ""; } - public String decodeAtIndex2(String _s, int _k) { - StringBuilder tape = new StringBuilder(); - CHARS: for (char c : _s.toCharArray()) { - if (Character.isDigit(c)) { - String curr = tape.toString(); - if (!curr.isEmpty()) { - int digit = c - '0'; - for (int i = 1; i < digit; i++) { - tape.append(curr); - if (tape.length() >= _k) { - break CHARS; - } - } - } - } else { - tape.append(c); - } - if (tape.length() >= _k) { - break; - } - } - String result = tape.substring(_k - 1, _k); - tape.setLength(0); - tape = null; - System.gc(); - return result; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0881.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0881.java index 9046bfda..f9e7c449 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0881.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0881.java @@ -14,7 +14,7 @@ class Problem0881 extends LeetcodeProblem { * @param _limit maximum weight of one boat * @return number of boats required to carry all people */ - public int numRescueBoats(int[] _people, int _limit) { + int numRescueBoats(int[] _people, int _limit) { int nbBoats = 0; Arrays.sort(_people); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0886.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0886.java index e0a50009..343a3c9a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0886.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0886.java @@ -13,7 +13,7 @@ class Problem0886 extends LeetcodeProblem { private int[] p; - public boolean possibleBipartition(int _n, int[][] _dislikes) { + boolean possibleBipartition(int _n, int[][] _dislikes) { p = new int[_n]; @SuppressWarnings("unchecked") List[] g = new List[_n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0887.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0887.java index 50e7ac8f..599b8c97 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0887.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0887.java @@ -9,7 +9,7 @@ class Problem0887 extends LeetcodeProblem { private int[][] f; - public int superEggDrop(int _k, int _n) { + int superEggDrop(int _k, int _n) { f = new int[_n + 1][_k + 1]; return dfs(_n, _k); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0891.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0891.java index 57e7a691..c280f4b8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0891.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0800/Problem0891.java @@ -11,7 +11,7 @@ class Problem0891 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int sumSubseqWidths(int[] _nums) { + int sumSubseqWidths(int[] _nums) { Arrays.sort(_nums); long ans = 0; long p = 1; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0902.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0902.java index e7940d5d..de38ddba 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0902.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0902.java @@ -15,7 +15,7 @@ class Problem0902 extends LeetcodeProblem { private final int[][] dp = new int[12][2]; private final Set s = new HashSet<>(); - public int atMostNGivenDigitSet(String[] _digits, int _n) { + int atMostNGivenDigitSet(String[] _digits, int _n) { for (var e : dp) { Arrays.fill(e, -1); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0909.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0909.java index 325f85a9..5bb93747 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0909.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0909.java @@ -12,7 +12,7 @@ class Problem0909 extends LeetcodeProblem { private int n; - public int snakesAndLadders(int[][] _board) { + int snakesAndLadders(int[][] _board) { n = _board.length; Deque q = new ArrayDeque<>(); q.offer(1); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0913.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0913.java index 397c64c4..b41f7f55 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0913.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0913.java @@ -23,7 +23,7 @@ class Problem0913 extends LeetcodeProblem { private int[][] g; - public int catMouseGame(int[][] _graph) { + int catMouseGame(int[][] _graph) { int n = _graph.length; g = _graph; int[][][] res = new int[n][n][2]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0920.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0920.java index f624f9d2..60ade60d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0920.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0920.java @@ -12,7 +12,7 @@ class Problem0920 extends LeetcodeProblem { private static final int MOD = (int) (1e9 + 7); - public int numMusicPlaylists(final int _songCount, final int _playlistLen, final int _repeatAfterCount) { + int numMusicPlaylists(final int _songCount, final int _playlistLen, final int _repeatAfterCount) { int[] used = new int[_songCount + 1]; Map memo = new HashMap<>(); int ways = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0928.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0928.java index b51d5979..fcfc39eb 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0928.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0928.java @@ -12,7 +12,7 @@ class Problem0928 extends LeetcodeProblem { private int[] p; private int[] size; - public int minMalwareSpread(int[][] _graph, int[] _initial) { + int minMalwareSpread(int[][] _graph, int[] _initial) { int n = _graph.length; p = new int[n]; size = new int[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0934.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0934.java index f611f8b4..b32253f2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0934.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0934.java @@ -11,7 +11,7 @@ class Problem0934 extends LeetcodeProblem { private static final int[][] DIRECTIONS = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; - public static int shortestBridge(int[][] _grid) { + static int shortestBridge(int[][] _grid) { final int len = _grid.length; for (int x = 0; x < len; x++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0940.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0940.java index f18b54a1..ced2de5c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0940.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0940.java @@ -9,7 +9,7 @@ class Problem0940 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int distinctSubseqII(String _s) { + int distinctSubseqII(String _s) { int[] dp = new int[26]; int ans = 0; for (int i = 0; i < _s.length(); i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946.java index 0df75eaf..7cf41540 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946.java @@ -2,8 +2,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Stack; - /** * 946. Validate Stack Sequences. */ @@ -24,17 +22,4 @@ boolean validateStackSequences(final int[] _arrPushed, final int[] _arrPopped) { return idxStack < 0; } - public boolean validateStackSequences2(int[] _arrPushed, int[] _arrPopped) { - Stack st = new Stack<>(); - int idxPop = 0; - for (int pushed : _arrPushed) { - st.push(pushed); - while (!st.empty() && st.peek() == _arrPopped[idxPop]) { - st.pop(); - idxPop++; - } - } - return st.empty(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0947.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0947.java index 9cf2d27b..13909261 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0947.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0947.java @@ -12,7 +12,7 @@ class Problem0947 extends LeetcodeProblem { private int[] p; - public int removeStones(int[][] _stones) { + int removeStones(int[][] _stones) { int n = 10010; p = new int[n << 1]; for (int i = 0; i < p.length; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0952.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0952.java index a5d99e4f..50ceb828 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0952.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0952.java @@ -33,7 +33,7 @@ int largestComponentSize(int[] _nums) { return ans; } - public static class UnionFind { + static class UnionFind { private final int[] p; UnionFind(int _n) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0958.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0958.java index d8a83616..bfa99bed 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0958.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0958.java @@ -41,33 +41,4 @@ boolean isCompleteTree(TreeNode _root) { return q.isEmpty(); } - boolean isCompleteTree2(TreeNode _node) { - // a null/empty tree is complete - if (_node == null) { - return true; - } - - // create queue to store tree nodes in level order - final Queue q = new LinkedList<>(); - q.add(_node); - - // traverse tree in level order - while (q.peek() != null) { - // remove the first node from the queue - TreeNode node = q.poll(); - // add left and right child nodes of current node to queue - q.offer(node.left); - q.offer(node.right); - } - - // remove any remaining null nodes from end of queue - while (!q.isEmpty() && q.peek() == null) { - q.poll(); - } - - // Check if there are remaining nodes in queue - // If so, tree is incomplete - return q.isEmpty(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0959.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0959.java index a4d32f1d..bd48f8b3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0959.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0959.java @@ -10,7 +10,7 @@ class Problem0959 extends LeetcodeProblem { private int[] p; private int size; - public int regionsBySlashes(String[] _grid) { + int regionsBySlashes(String[] _grid) { int n = _grid.length; size = n * n * 4; p = new int[size]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0964.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0964.java index c741dc72..06010990 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0964.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0964.java @@ -13,7 +13,7 @@ class Problem0964 extends LeetcodeProblem { private int x; private final Map f = new HashMap<>(); - public int leastOpsExpressTarget(int _x, int _target) { + int leastOpsExpressTarget(int _x, int _target) { x = _x; return dfs(_target); } diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0971.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0971.java index db0a5919..0c96e500 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0971.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0971.java @@ -16,7 +16,7 @@ class Problem0971 extends LeetcodeProblem { private int[] voyage; private final List ans = new ArrayList<>(); - public List flipMatchVoyage(TreeNode _root, int[] _voyage) { + List flipMatchVoyage(TreeNode _root, int[] _voyage) { voyage = _voyage; ok = true; dfs(_root); diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0975.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0975.java index 7dd3a33d..b66cb494 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0975.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0975.java @@ -13,7 +13,7 @@ class Problem0975 extends LeetcodeProblem { private Integer[][] f; private int[][] g; - public int oddEvenJumps(int[] _arr) { + int oddEvenJumps(int[] _arr) { TreeMap tm = new TreeMap<>(); n = _arr.length; f = new Integer[n][2]; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0980.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0980.java index 6c97bfc1..0f4cc5a4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0980.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0980.java @@ -7,7 +7,7 @@ class Problem0980 extends LeetcodeProblem { private static final int[] DIRS = new int[] {0, 1, 0, -1, 0}; private int paths = 0; - public int uniquePathsIII(int[][] _grid) { + int uniquePathsIII(int[][] _grid) { int[] start = findStart(_grid); int nbRows = _grid.length; int nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0989.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0989.java index 64e2954b..5bd28985 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0989.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0989.java @@ -11,18 +11,8 @@ class Problem0989 extends LeetcodeProblem { List addToArrayForm(int[] _num, int _k) { - return addToArrayForm2(_num, _k); - } - - public List addToArrayForm1(int[] _num, int _k) { - String strNum = java.util.Arrays.stream(_num).mapToObj(i -> i + "").collect(java.util.stream.Collectors.joining()); - java.math.BigInteger sum = new java.math.BigInteger(strNum).add(java.math.BigInteger.valueOf(_k)); - return java.util.Arrays.stream(sum.toString().split("")).map(Integer::parseInt).toList(); - } - - public List addToArrayForm2(int[] _num, int _k) { - final int len = _num.length; - final List list = new LinkedList<>(); + int len = _num.length; + List list = new LinkedList<>(); int idx = len - 1; while (idx >= 0 || _k != 0) { diff --git a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0999.java b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0999.java index 056da8ae..2553b3e3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0999.java +++ b/src/main/java/io/github/spannm/leetcode/lc0/lc0900/Problem0999.java @@ -5,7 +5,7 @@ class Problem0999 extends LeetcodeProblem { private static final int[] DIRS = new int[] {0, 1, 0, -1, 0}; - public int numRookCaptures(char[][] _board) { + int numRookCaptures(char[][] _board) { int nbRows = _board.length; int nbCols = _board[0].length; int rowR = -1; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1007.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1007.java index 14f695f2..2494ccef 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1007.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1007.java @@ -11,7 +11,7 @@ class Problem1007 extends LeetcodeProblem { private int[] tops; private int[] bottoms; - public int minDominoRotations(int[] _tops, int[] _bottoms) { + int minDominoRotations(int[] _tops, int[] _bottoms) { n = _tops.length; tops = _tops; bottoms = _bottoms; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1008.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1008.java index 1353bfd7..729669fc 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1008.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1008.java @@ -6,7 +6,7 @@ class Problem1008 extends LeetcodeProblem { private int i = 0; - public TreeNode bstFromPreorder(int[] _preorder) { + TreeNode bstFromPreorder(int[] _preorder) { return bstFromPreorder(_preorder, Integer.MAX_VALUE); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011.java index af31867f..273b85ee 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011.java @@ -2,7 +2,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.stream.IntStream; @@ -12,34 +11,9 @@ */ class Problem1011 extends LeetcodeProblem { - int shipWithinDays1(int[] _weights, int _days) { - int nbWeights = _weights.length; - long totalWeight = Arrays.stream(_weights).sum(); - - long targetWeightPerDay = Math.round((double) totalWeight / _days); - int weightCurrDay = 0; - int maxWeightPerDay = 0; - - for (int i = 0, day = 1; i < nbWeights; day++) { - while (i < nbWeights - && (day == 1 - ? weightCurrDay < targetWeightPerDay - : weightCurrDay + _weights[i] <= targetWeightPerDay + 1)) { - weightCurrDay += _weights[i]; - i++; - } - if (day == 1) { - targetWeightPerDay = weightCurrDay; - } - maxWeightPerDay = Math.max(maxWeightPerDay, weightCurrDay); - weightCurrDay = 0; - } - return maxWeightPerDay; - } - // Function to find the least weight capacity of a boat // to ship all the weights within _days days - public int shipWithinDays2(final int[] _weights, final int _days) { + int shipWithinDays(final int[] _weights, final int _days) { final IntSummaryStatistics summaryStats = IntStream.of(_weights).summaryStatistics(); final int nbWeights = (int) summaryStats.getCount(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1012.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1012.java index 1305a897..d1ec9914 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1012.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1012.java @@ -10,7 +10,7 @@ class Problem1012 extends LeetcodeProblem { private final int[] nums = new int[11]; private final Integer[][] dp = new Integer[11][1 << 11]; - public int numDupDigitsAtMostN(int _n) { + int numDupDigitsAtMostN(int _n) { return _n - f(_n); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1026.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1026.java index 789d7879..cbdddd52 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1026.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1026.java @@ -6,7 +6,7 @@ class Problem1026 extends LeetcodeProblem { private int maxDiff = 0; - public int maxAncestorDiff(TreeNode _root) { + int maxAncestorDiff(TreeNode _root) { dfs(_root); return maxDiff; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1034.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1034.java index 281a7019..578f317a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1034.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1034.java @@ -13,7 +13,7 @@ class Problem1034 extends LeetcodeProblem { private int n; private boolean[][] vis; - public int[][] colorBorder(int[][] _grid, int _row, int _col, int _color) { + int[][] colorBorder(int[][] _grid, int _row, int _col, int _color) { grid = _grid; color = _color; m = _grid.length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1036.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1036.java index 667dd778..5b235ab4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1036.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1036.java @@ -14,7 +14,7 @@ class Problem1036 extends LeetcodeProblem { private static final int[][] DIRS = new int[][] {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; private final Set blocked = new HashSet<>(); - public boolean isEscapePossible(int[][] _blocked, int[] _source, int[] _target) { + boolean isEscapePossible(int[][] _blocked, int[] _source, int[] _target) { blocked.clear(); for (int[] b : _blocked) { blocked.add(b[0] * N + b[1]); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1039.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1039.java index 7dde56da..2c55f648 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1039.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1039.java @@ -10,7 +10,7 @@ class Problem1039 extends LeetcodeProblem { private int[] values; private Integer[][] f; - public int minScoreTriangulation(int[] _values) { + int minScoreTriangulation(int[] _values) { int n = _values.length; values = _values; f = new Integer[n][n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1044.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1044.java index da38952d..47d18a51 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1044.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1044.java @@ -13,7 +13,7 @@ class Problem1044 extends LeetcodeProblem { private long[] p; private long[] h; - public String longestDupSubstring(String _s) { + String longestDupSubstring(String _s) { int base = 131; int n = _s.length(); p = new long[n + 10]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1056.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1056.java index 49ec9cc5..c5f0776d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1056.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1056.java @@ -12,7 +12,7 @@ class Problem1056 extends LeetcodeProblem { 6, 9, 9, 6); - public boolean confusingNumber(int _n) { + boolean confusingNumber(int _n) { if (_n == 0) { return false; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1059.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1059.java index 72b17fa3..041eee6b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1059.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1059.java @@ -17,7 +17,7 @@ class Problem1059 extends LeetcodeProblem { private int k; @SuppressWarnings("unchecked") - public boolean leadsToDestination(int _n, int[][] _edges, int _source, int _destination) { + boolean leadsToDestination(int _n, int[][] _edges, int _source, int _destination) { vis = new boolean[_n]; g = new List[_n]; k = _destination; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1066.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1066.java index 7c480b68..3947b4d1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1066.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1066.java @@ -5,7 +5,7 @@ class Problem1066 extends LeetcodeProblem { private int minSum = Integer.MAX_VALUE; - public int assignBikes(int[][] _workers, int[][] _bikes) { + int assignBikes(int[][] _workers, int[][] _bikes) { backtracking(_workers, _bikes, 0, new boolean[_bikes.length], 0); return minSum; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1067.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1067.java index a88d150b..4d93a965 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1067.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1067.java @@ -13,7 +13,7 @@ class Problem1067 extends LeetcodeProblem { private final int[] a = new int[11]; private final int[][] dp = new int[11][11]; - public int digitsCount(int _d, int _low, int _high) { + int digitsCount(int _d, int _low, int _high) { d = _d; return f(_high) - f(_low - 1); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1088.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1088.java index 4b368091..4f901063 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1088.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1088.java @@ -10,7 +10,7 @@ class Problem1088 extends LeetcodeProblem { private final int[] d = {0, 1, -1, -1, -1, -1, 9, -1, 8, 6}; private String s; - public int confusingNumberII(int _n) { + int confusingNumberII(int _n) { s = String.valueOf(_n); return dfs(0, 1, 0); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1093.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1093.java index 19f3e0d9..4653122e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1093.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1000/Problem1093.java @@ -9,7 +9,7 @@ class Problem1093 extends LeetcodeProblem { private int[] count; - public double[] sampleStats(int[] _count) { + double[] sampleStats(int[] _count) { count = _count; int mi = 1 << 30; int mx = -1; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1101.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1101.java index e6e0c193..afa51e10 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1101.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1101.java @@ -12,7 +12,7 @@ class Problem1101 extends LeetcodeProblem { private int[] p; - public int earliestAcq(int[][] _logs, int _n) { + int earliestAcq(int[][] _logs, int _n) { Arrays.sort(_logs, Comparator.comparingInt(a -> a[0])); p = new int[_n]; for (int i = 0; i < _n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1114.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1114.java index d89c1eaa..b62d3c45 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1114.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1114.java @@ -68,7 +68,7 @@ private synchronized void doAction(int _order, Runnable _r) throws InterruptedEx } @SuppressWarnings("PMD.EmptyCatchBlock") - public static void main(String[] _args) throws InterruptedException { + static void main(String[] _args) throws InterruptedException { Foo foo = new Foo(2, 1, 3); List threads = new ArrayList<>(List.of( new Thread(() -> { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1117.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1117.java index f163af79..c48e01a2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1117.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1117.java @@ -15,7 +15,7 @@ class Problem1117 extends LeetcodeProblem { private final Semaphore hSem = new Semaphore(2); private final Semaphore oSem = new Semaphore(1); - public void hydrogen(Runnable _releaseHydrogen) { + void hydrogen(Runnable _releaseHydrogen) { try { hSem.acquire(); barrier.await(); @@ -28,7 +28,7 @@ public void hydrogen(Runnable _releaseHydrogen) { } - public void oxygen(Runnable _releaseOxygen) { + void oxygen(Runnable _releaseOxygen) { try { oSem.acquire(); barrier.await(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1120.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1120.java index ecc9b214..f2e2fa38 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1120.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1120.java @@ -10,7 +10,7 @@ class Problem1120 extends LeetcodeProblem { private double ans; - public double maximumAverageSubtree(TreeNode _root) { + double maximumAverageSubtree(TreeNode _root) { dfs(_root); return ans; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1135.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1135.java index f36f65fd..d2a2cc97 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1135.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1135.java @@ -12,7 +12,7 @@ class Problem1135 extends LeetcodeProblem { private int[] p; - public int minimumCost(int _n, int[][] _connections) { + int minimumCost(int _n, int[][] _connections) { Arrays.sort(_connections, Comparator.comparingInt(a -> a[2])); p = new int[_n]; for (int i = 0; i < _n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1154.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1154.java index 56d23d06..12fb628f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1154.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1154.java @@ -7,7 +7,7 @@ class Problem1154 extends LeetcodeProblem { private final Calendar cal = Calendar.getInstance(); - public int dayOfYear(String _date) { + int dayOfYear(String _date) { int year = Integer.parseInt(_date.substring(0, 4)); int month = Integer.parseInt(_date.substring(5, 7)); int day = Integer.parseInt(_date.substring(8, 10)); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1175.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1175.java index 3f20ee26..63562a2e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1175.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1175.java @@ -9,14 +9,14 @@ class Problem1175 extends LeetcodeProblem { static final int MOD = 1000000007; - public static int numPrimeArrangements(int _n) { + static int numPrimeArrangements(int _n) { int numberOfPrimes = generatePrimes(_n); BigInteger x = factorial(numberOfPrimes); BigInteger y = factorial(_n - numberOfPrimes); return x.multiply(y).mod(BigInteger.valueOf(MOD)).intValue(); } - public static BigInteger factorial(int _n) { + static BigInteger factorial(int _n) { BigInteger fac = BigInteger.ONE; for (int i = 2; i <= _n; i++) { fac = fac.multiply(BigInteger.valueOf(i)); @@ -24,7 +24,7 @@ public static BigInteger factorial(int _n) { return fac.mod(BigInteger.valueOf(MOD)); } - public static int generatePrimes(int _n) { + static int generatePrimes(int _n) { boolean[] prime = new boolean[_n + 1]; Arrays.fill(prime, 2, _n + 1, true); for (int i = 2; i * i <= _n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1177.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1177.java index 32be26d4..5311cf35 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1177.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1177.java @@ -11,7 +11,7 @@ class Problem1177 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public List canMakePaliQueries(String _s, int[][] _queries) { + List canMakePaliQueries(String _s, int[][] _queries) { int len = _s.length(); int[][] ss = new int[len + 1][26]; for (int i = 1; i <= len; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1192.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1192.java index 76badf9f..9f2819bc 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1192.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1100/Problem1192.java @@ -17,7 +17,7 @@ class Problem1192 extends LeetcodeProblem { private int[] dfn; private int[] low; - public List> criticalConnections(int _n, List> _connections) { + List> criticalConnections(int _n, List> _connections) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1202.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1202.java index 30271441..b5501394 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1202.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1202.java @@ -12,7 +12,7 @@ class Problem1202 extends LeetcodeProblem { private int[] p; - public String smallestStringWithSwaps(String _s, List> _pairs) { + String smallestStringWithSwaps(String _s, List> _pairs) { int n = _s.length(); p = new int[n]; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1210.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1210.java index d682b1ac..78d39102 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1210.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1210.java @@ -15,7 +15,7 @@ class Problem1210 extends LeetcodeProblem { private boolean[][] vis; private final Deque q = new ArrayDeque<>(); - public int minimumMoves(int[][] _grid) { + int minimumMoves(int[][] _grid) { grid = _grid; n = _grid.length; vis = new boolean[n * n][2]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1218.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1218.java index 7308dd25..d9d5b62d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1218.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1218.java @@ -11,24 +11,7 @@ */ class Problem1218 extends LeetcodeProblem { - int longestSubsequence2(final int[] _arr, final int _difference) { - return calc2(0, -10000, _arr, _arr.length, _difference); - } - - static int calc2(final int _index, final int _prev, int[] _arr, int _len, int _difference) { - if (_index >= _len) { - return 0; - } - - int take = 0; - int notake = calc2(_index + 1, _prev, _arr, _len, _difference); - if (_prev == -10000 || _arr[_index] - _prev == _difference) { - take = 1 + calc2(_index + 1, _arr[_index], _arr, _len, _difference); - } - return Math.max(take, notake); - } - - public int longestSubsequence(final int[] _arr, final int _difference) { + int longestSubsequence(final int[] _arr, final int _difference) { final int len = _arr.length; final Map dp = new HashMap<>(len); // Stores max length at each index diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1223.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1223.java index 6c9a4535..eb620293 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1223.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1223.java @@ -10,7 +10,7 @@ class Problem1223 extends LeetcodeProblem { private Integer[][][] f; private int[] rollMax; - public int dieSimulator(int _n, int[] _rollMax) { + int dieSimulator(int _n, int[] _rollMax) { f = new Integer[_n][7][16]; rollMax = _rollMax; return dfs(0, 0, 0); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1224.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1224.java index 13f05602..f9254a1f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1224.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1224.java @@ -12,7 +12,7 @@ class Problem1224 extends LeetcodeProblem { private final int[] cnt = new int[100010]; private final int[] ccnt = new int[100010]; - public int maxEqualFreq(int[] _nums) { + int maxEqualFreq(int[] _nums) { Arrays.fill(cnt, 0); Arrays.fill(ccnt, 0); int ans = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1236.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1236.java index 07b23784..0a7f2b2c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1236.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1236.java @@ -15,7 +15,7 @@ class Problem1236 extends LeetcodeProblem { private Set ans; - public List crawl(String _startUrl, HtmlParser _htmlParser) { + List crawl(String _startUrl, HtmlParser _htmlParser) { ans = new HashSet<>(); dfs(_startUrl, _htmlParser); return new ArrayList<>(ans); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1240.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1240.java index a73b9611..5b116df1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1240.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1240.java @@ -12,7 +12,7 @@ class Problem1240 extends LeetcodeProblem { private int[] filled; private int ans; - public int tilingRectangle(int _n, int _m) { + int tilingRectangle(int _n, int _m) { n = _n; m = _m; ans = _n * _m; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1245.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1245.java index 0ddbee26..2d2db6d9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1245.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1245.java @@ -17,7 +17,7 @@ class Problem1245 extends LeetcodeProblem { private int next; private int ans; - public int treeDiameter(int[][] _edges) { + int treeDiameter(int[][] _edges) { int n = _edges.length; ans = 0; g = new HashMap<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1263.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1263.java index e6edd414..a6b1a3a1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1263.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1263.java @@ -14,7 +14,7 @@ class Problem1263 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int minPushBox(char[][] _grid) { + int minPushBox(char[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1292.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1292.java index 6a491050..ba1c2b6b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1292.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1200/Problem1292.java @@ -12,7 +12,7 @@ class Problem1292 extends LeetcodeProblem { private int threshold; private int[][] s; - public int maxSideLength(int[][] _mat, int _threshold) { + int maxSideLength(int[][] _mat, int _threshold) { nbRows = _mat.length; nbCols = _mat[0].length; threshold = _threshold; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1301.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1301.java index 7a31a80c..26ce3e8d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1301.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1301.java @@ -16,7 +16,7 @@ class Problem1301 extends LeetcodeProblem { private int[][] g; private final int mod = (int) 1e9 + 7; - public int[] pathsWithMaxScore(List _board) { + int[] pathsWithMaxScore(List _board) { board = _board; sz = _board.size(); f = new int[sz][sz]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1312.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1312.java index c2cf752c..01f1ede0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1312.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1312.java @@ -11,7 +11,7 @@ class Problem1312 extends LeetcodeProblem { // Keeping the longest palindromic subsequence common and rest elements will be add to the string resulting in the // min number of operations. // length of given string - longest palindromic string length will be the answer - public int minInsertions(String _str) { + int minInsertions(String _str) { return _str.length() - calc(_str); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1316.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1316.java index 2aa238af..7217c883 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1316.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1316.java @@ -13,7 +13,7 @@ class Problem1316 extends LeetcodeProblem { private long[] h; private long[] p; - public int distinctEchoSubstrings(String text) { + int distinctEchoSubstrings(String text) { int n = text.length(); int base = 131; h = new long[n + 10]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1351.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1351.java index 3f8f54cb..0c3904c8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1351.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1351.java @@ -29,21 +29,4 @@ static int countNegatives(final int[][] _grid) { return count; } - public int countNegatives2(final int[][] _grid) { - int rowCount = _grid.length; - int colCount = _grid[0].length; - int count = 0; - - for (int row = rowCount - 1; row >= 0; row--) { - for (int col = colCount - 1; col >= 0; col--) { - if (_grid[row][col] >= 0) { - break; - } - count++; - } - } - - return count; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1360.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1360.java index 9e9a0986..9100f6e1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1360.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1360.java @@ -11,7 +11,7 @@ int daysBetweenDates(String _date1, String _date2) { - julianDay(Integer.parseInt(strings2[0]), Integer.parseInt(strings2[1]), Integer.parseInt(strings2[2]))); } - public int julianDay(int _year, int _month, int _day) { + int julianDay(int _year, int _month, int _day) { int a = (14 - _month) / 12; int y = _year + 4800 - a; int m = _month + 12 * a - 3; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1366.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1366.java index 5d63479e..b065e649 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1366.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1366.java @@ -14,7 +14,7 @@ static class Node { } } - public String rankTeams(String[] _votes) { + String rankTeams(String[] _votes) { Node[] nodes = new Node[26]; for (int i = 0; i < 26; i++) { nodes[i] = new Node((char) (i + 'A')); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1367.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1367.java index 41cdd4a1..afd61990 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1367.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1367.java @@ -10,7 +10,7 @@ class Problem1367 extends LeetcodeProblem { private final List> paths = new ArrayList<>(); - public boolean isSubPath(ListNode _head, TreeNode _root) { + boolean isSubPath(ListNode _head, TreeNode _root) { List list = getList(_head); findAllPaths(_root, new ArrayList<>()); for (List path : paths) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1376.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1376.java index b205292a..7ddb7d30 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1376.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1376.java @@ -2,9 +2,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.*; -import java.util.stream.IntStream; - /** * 1376. Time Needed to Inform All * Employees. @@ -29,42 +26,4 @@ static int dfs(final int _id, final int[] _managers, final int[] _times) { return _times[_id]; } - int numOfMinutes1(final int _count, int _headid, int[] _managers, int[] _times) { - final Map> graph = new HashMap<>(); - for (int i = 0; i < _count; i++) { - graph.computeIfAbsent(_managers[i], k -> new HashSet<>()).add(i); - } - final Queue q = new ArrayDeque<>(); - // the first value is the id, and the second is the time to reach the children of id - q.offer(new int[] {-1, 0}); - int max = 0; - while (!q.isEmpty()) { - int size = q.size(); - while (size-- > 0) { - int[] curr = q.poll(); - max = Math.max(max, curr[1]); - if (graph.containsKey(curr[0])) { - for (int next : graph.get(curr[0])) { - q.offer(new int[] {next, curr[1] + _times[next]}); - } - } - } - } - return max; - } - - int numOfMinutes2(final int _count, int _headId, int[] _manager, int[] _times) { - if (_count == 1) { - return _times[0]; - } - - return IntStream.range(0, _count) - .filter(id -> id != _headId) - .mapToObj(id -> _manager[id]) - .distinct() - .map(id -> _times[id]) - .mapToInt(i -> i) - .sum(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1383.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1383.java index fb1ed82d..b3eacebb 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1383.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1383.java @@ -13,7 +13,7 @@ class Problem1383 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int maxPerformance(int n, int[] speed, int[] efficiency, int k) { + int maxPerformance(int n, int[] speed, int[] efficiency, int k) { int[][] t = new int[n][2]; for (int i = 0; i < n; i++) { t[i] = new int[] {speed[i], efficiency[i]}; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1391.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1391.java index 4ef6b4f3..fd303b1e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1391.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1300/Problem1391.java @@ -12,7 +12,7 @@ class Problem1391 extends LeetcodeProblem { private int nbCols; private int[] p; - public boolean hasValidPath(int[][] _grid) { + boolean hasValidPath(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1424.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1424.java index c5a3d345..f334fe4e 100755 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1424.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1424.java @@ -43,36 +43,4 @@ int[] findDiagonalOrder(List> _nums) { return output; } - public int[] findDiagonalOrderTLE(List> _nums) { - int maxColIdx = 0; - int maxRowIdx = _nums.size() - 1; - List rowSizes = new ArrayList<>(maxRowIdx + 1); - List output = new ArrayList<>(); - - // loop per rows - for (int r = 0; r <= maxRowIdx; r++) { - rowSizes.add(_nums.get(r).size()); - // loop per columns - for (int c = 0, r2 = r; c <= r; c++, r2--) { - if (c < rowSizes.get(r2)) { - output.add(_nums.get(r2).get(c)); - } - } - } - - maxColIdx = java.util.Collections.max(rowSizes) - 1; - - // loop per columns starting at 2nd colum in last row - for (int c = 1; c <= maxColIdx; c++) { - // loop per rows - for (int r = maxRowIdx, c2 = c; r >= 0; r--, c2++) { - if (c2 < rowSizes.get(r)) { - output.add(_nums.get(r).get(c2)); - } - } - } - - return output.stream().mapToInt(i -> i).toArray(); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1430.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1430.java index 3fc728b2..e6baf550 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1430.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1430.java @@ -10,7 +10,7 @@ class Problem1430 extends LeetcodeProblem { private int[] arr; - public boolean isValidSequence(TreeNode _root, int[] _arr) { + boolean isValidSequence(TreeNode _root, int[] _arr) { arr = _arr; return dfs(_root, 0); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1431.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1431.java index 6a19addb..63047d2a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1431.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1431.java @@ -2,7 +2,6 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -17,18 +16,4 @@ static List kidsWithCandies(int[] _candies, int _extraCandies) { return Arrays.stream(_candies).mapToObj(i -> i >= max).toList(); } - static List kidsWithCandies2(int[] _candies, int _extraCandies) { - final int len = _candies.length; - int max = 0; - for (int candy : _candies) { - max = Math.max(max, candy); - } - max -= _extraCandies; - final List results = new ArrayList<>(len); - for (int i = 0; i < len; i++) { - results.add(i, _candies[i] >= max); - } - return results; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1444.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1444.java index 484510bc..f7354271 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1444.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1444.java @@ -14,7 +14,7 @@ class Problem1444 extends LeetcodeProblem { private static final byte EMPTY = 0; private static final byte APPLE = 1; - public int ways(final String[] _pizza, final int _nbPeople) { + int ways(final String[] _pizza, final int _nbPeople) { final byte nbRows = (byte) _pizza.length; final byte nbCols = (byte) _pizza[0].length(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1448.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1448.java index 7ced82ae..42414693 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1448.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1448.java @@ -10,7 +10,7 @@ class Problem1448 extends LeetcodeProblem { private int count; - public int goodNodes(TreeNode _root) { + int goodNodes(TreeNode _root) { return dfs(_root, new PriorityQueue<>(Comparator.reverseOrder())); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1455.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1455.java index ee5f32b7..22c4f6d1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1455.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1455.java @@ -5,7 +5,7 @@ class Problem1455 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public int isPrefixOfWord(String _sentence, String _searchWord) { + int isPrefixOfWord(String _sentence, String _searchWord) { String[] words = _sentence.split(" "); for (int i = 0; i < words.length; i++) { if (words[i].startsWith(_searchWord)) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464.java index ac83982c..3acdad52 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464.java @@ -20,17 +20,4 @@ int maxProduct(int[] _nums) { return (max1 - 1) * (max2 - 1); } - public int maxProduct2(int[] _nums) { - int maxProduct = 0; - for (int i = 0; i < _nums.length; i++) { - for (int j = 0; j < _nums.length; j++) { - if (i != j) { - int product = (_nums[i] - 1) * (_nums[j] - 1); - maxProduct = Math.max(maxProduct, product); - } - } - } - return maxProduct; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1467.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1467.java index c42269c8..4b0ee013 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1467.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1467.java @@ -16,7 +16,7 @@ class Problem1467 extends LeetcodeProblem { private int[] balls; private final Map, Long> f = new HashMap<>(); - public double getProbability(int[] _balls) { + double getProbability(int[] _balls) { int mx = 0; for (int x : _balls) { n += x; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491.java index 86057e61..d368c894 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491.java @@ -2,26 +2,13 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; - /** * 1491. Average Salary * Excluding the Minimum and Maximum Salary. */ class Problem1491 extends LeetcodeProblem { - static double average1(int[] _salaries) { - Arrays.sort(_salaries); - - int len = _salaries.length; - int sum = 0; - for (int i = 1; i < len - 1; i++) { - sum += _salaries[i]; - } - return (double) sum / (len - 2); - } - - static double average(final int[] _salaries) { + double average(final int[] _salaries) { final int len = _salaries.length; int min = Integer.MAX_VALUE; int max = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1493.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1493.java index 04b788e0..8009bbb9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1493.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1400/Problem1493.java @@ -6,42 +6,9 @@ * 1493. Longest Subarray of * 1's After Deleting One Element. */ -public final class Problem1493 extends LeetcodeProblem { +public class Problem1493 extends LeetcodeProblem { - int longestSubarray1(final int[] _nums) { - boolean foundOther = false; // at least one digit != 1 overall - boolean startSeq = false; // sequence started - boolean seqFoundOther = false; // one digit != 1 in sequence - int count = 0; - int max = 0; - for (int n : _nums) { - if (n == 1) { - count++; - startSeq = true; - } else { - foundOther = true; - if (startSeq) { - if (!seqFoundOther) { - seqFoundOther = true; - } else { - max = Math.max(max, count); - startSeq = false; // found more than one other - seqFoundOther = false; - count = 0; - } - } - } - } - if (count > 0) { // handle last - max = Math.max(max, count); - } - if (!foundOther) { - max--; - } - return max; - } - - public int longestSubarray(final int[] _nums) { + int longestSubarray(final int[] _nums) { final int len = _nums.length; int c1 = 0; // number of ones after last 0 diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1510.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1510.java index 422ee0ee..fdb74e0b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1510.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1510.java @@ -9,7 +9,7 @@ class Problem1510 extends LeetcodeProblem { private Boolean[] f; - public boolean winnerSquareGame(int n) { + boolean winnerSquareGame(int n) { f = new Boolean[n + 1]; return dfs(n); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1519.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1519.java index fa8639c4..4da663ac 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1519.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1519.java @@ -16,7 +16,7 @@ class Problem1519 extends LeetcodeProblem { private int[] ans; private int[] cnt; - public int[] countSubTrees(int _n, int[][] _edges, String _labels) { + int[] countSubTrees(int _n, int[][] _edges, String _labels) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1539.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1539.java index c783a58a..3a960cf2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1539.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1539.java @@ -22,42 +22,4 @@ int findKthPositive(int[] _arr, int _k) { return left + _k; } - public int findKthPositive1(int[] _arr, int _k) { - final int len = _arr.length; - int totalMissing = _arr[len - 1] - len; - if (totalMissing < _k) { - // kth is outside of array - return _arr[len - 1] + _k - totalMissing; - } - - return findKthPositive1a(_arr, _k, 0, len - 1); - } - - int findKthPositive1a(int[] _arr, int _k, int _fromIndex, int _toIndex) { - if (_toIndex - _fromIndex <= 3) { - int nthMissing = 0; - for (int idx = _fromIndex + 1; idx <= _toIndex; idx++) { - if (_arr[idx - 1] < _arr[idx] - 1) { - for (int num = _arr[idx - 1]; num < _arr[idx]; num++) { - nthMissing++; - if (nthMissing == _k) { - return num; - } - } - } - } - } - - // half the array - int splitIndex = (_toIndex - _fromIndex) / 2; - int totalMissingLeft = _arr[splitIndex] - (splitIndex + 1); // last number minus length - if (totalMissingLeft >= _k) { - // continue with left - return findKthPositive1a(_arr, _k, _fromIndex, splitIndex); - } else { - // continue with right - return findKthPositive1a(_arr, _k - totalMissingLeft, splitIndex + 1, _toIndex); - } - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1553.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1553.java index 372a7df8..a004b46c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1553.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1553.java @@ -12,7 +12,7 @@ class Problem1553 extends LeetcodeProblem { private final Map f = new HashMap<>(); - public int minDays(int _n) { + int minDays(int _n) { return dfs(_n); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1559.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1559.java index 70512f4e..be577666 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1559.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1559.java @@ -9,7 +9,7 @@ class Problem1559 extends LeetcodeProblem { private int[] p; - public boolean containsCycle(char[][] grid) { + boolean containsCycle(char[][] grid) { int m = grid.length; int n = grid[0].length; p = new int[m * n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1563.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1563.java index 5b516bcb..200223e2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1563.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1563.java @@ -11,7 +11,7 @@ class Problem1563 extends LeetcodeProblem { private int[] s; private Integer[][] f; - public int stoneGameV(int[] _stoneValue) { + int stoneGameV(int[] _stoneValue) { stoneValue = _stoneValue; int n = _stoneValue.length; s = new int[n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1568.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1568.java index 6623a1cd..1683f421 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1568.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1568.java @@ -13,7 +13,7 @@ class Problem1568 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int minDays(int[][] _grid) { + int minDays(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1569.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1569.java index 97d4f56b..5b8f7240 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1569.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1569.java @@ -14,7 +14,7 @@ class Problem1569 extends LeetcodeProblem { private static final int MOD = 1000000007; - public static int numOfWays(final int[] _nums) { + static int numOfWays(final int[] _nums) { final int sz = _nums.length; if (sz <= 2) { return 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1573.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1573.java index a1187a37..568c4056 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1573.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1573.java @@ -9,7 +9,7 @@ class Problem1573 extends LeetcodeProblem { private String s; - public int numWays(String _s) { + int numWays(String _s) { s = _s; int cnt = 0; int n = _s.length(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1593.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1593.java index 99d6bb3e..9dab1b4b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1593.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1593.java @@ -14,7 +14,7 @@ class Problem1593 extends LeetcodeProblem { private int ans = 1; private String s; - public int maxUniqueSplit(String _s) { + int maxUniqueSplit(String _s) { s = _s; dfs(0, 0); return ans; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1594.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1594.java index 5e93133c..933ec8cd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1594.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1500/Problem1594.java @@ -9,7 +9,7 @@ class Problem1594 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int maxProductPath(int[][] grid) { + int maxProductPath(int[][] grid) { int m = grid.length; int n = grid[0].length; long[][][] dp = new long[m][n][2]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1617.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1617.java index 5b2236e1..3a4ef3d6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1617.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1617.java @@ -16,7 +16,7 @@ class Problem1617 extends LeetcodeProblem { private int nxt; private int mx; - public int[] countSubgraphsForEachDiameter(int _n, int[][] _edges) { + int[] countSubgraphsForEachDiameter(int _n, int[][] _edges) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1621.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1621.java index b301423c..462832c1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1621.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1621.java @@ -9,7 +9,7 @@ class Problem1621 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int numberOfSets(int n, int k) { + int numberOfSets(int n, int k) { int[][] f = new int[n + 1][k + 1]; int[][] g = new int[n + 1][k + 1]; f[1][0] = 1; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1628.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1628.java index 96a2f220..3984da81 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1628.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1628.java @@ -9,7 +9,7 @@ class Problem1628 extends LeetcodeProblem { @SuppressWarnings("checkstyle:VisibilityModifierCheck") - public abstract static class Node { + abstract static class Node { Node left; Node right; String val; @@ -60,7 +60,7 @@ public List print(Node _node, List _list) { } - public static class TreeBuilder { + static class TreeBuilder { public Node buildTree(String[] _postfix) { Deque stack = new LinkedList<>(); for (String str : _postfix) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1631.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1631.java index b91b0e8c..b3227969 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1631.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1631.java @@ -10,7 +10,7 @@ class Problem1631 extends LeetcodeProblem { private int rowCount = 0; private int colCount = 0; - public int minimumEffortPath(int[][] _heights) { + int minimumEffortPath(int[][] _heights) { rowCount = _heights.length; colCount = _heights[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1648.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1648.java index 6a6a7772..77f4b9c6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1648.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1648.java @@ -11,7 +11,7 @@ class Problem1648 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int maxProfit(int[] inventory, int orders) { + int maxProfit(int[] inventory, int orders) { Arrays.sort(inventory); int n = inventory.length; for (int i = 0, j = n - 1; i < j; i++, j--) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1659.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1659.java index 28a87017..432e0e1c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1659.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1659.java @@ -13,7 +13,7 @@ class Problem1659 extends LeetcodeProblem { private final int[][] h = {{0, 0, 0}, {0, -60, -10}, {0, -10, 40}}; private Integer[][][][] memo; - public int getMaxGridHappiness(int _m, int _n, int _introvertsCount, int _extrovertsCount) { + int getMaxGridHappiness(int _m, int _n, int _introvertsCount, int _extrovertsCount) { m = _m; n = _n; p = (int) Math.pow(3, _n - 1); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1660.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1660.java index 8704ccac..e7d576e4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1660.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1660.java @@ -13,7 +13,7 @@ class Problem1660 extends LeetcodeProblem { private final Set vis = new HashSet<>(); - public TreeNode correctBinaryTree(TreeNode root) { + TreeNode correctBinaryTree(TreeNode root) { return dfs(root); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1675.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1675.java index df93a9c7..320d0ed7 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1675.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1675.java @@ -43,114 +43,4 @@ int minimumDeviation(int[] _nums) { return deviation; } - public int minimumDeviation2(int[] _nums) { - if (_nums == null) { - return 0; - } - final int len = _nums.length; - if (len <= 1) { - return 0; - } - - // sorted set (no dups) - SortedSet set = IntStream.of(_nums).boxed().collect(Collectors.toCollection(TreeSet::new)); - int deviation = set.last() - set.first(); - while (true) { - int first = set.first(); - int last = set.last(); - - int newFirst = first % 2 == 1 ? first * 2 : first; // odd -> can multiply by 2 - int deviationFirst = deviation; - - // calc new deviation - if (first != newFirst) { - set.remove(first); - boolean added = set.add(newFirst); - deviationFirst = set.last() - set.first(); - if (added) { - set.remove(newFirst); - } - set.add(first); - } - - int newLast = last % 2 == 0 ? last / 2 : last; // even -> can divide by 2 - int deviationLast = deviation; - - // calc new deviation - if (last != newLast) { - set.remove(last); - boolean added = set.add(newLast); - deviationLast = set.last() - set.first(); - if (added) { - set.remove(newLast); - } - set.add(last); - } - - // biggest gain? - if (deviationFirst < deviation && deviationFirst < deviationLast) { - set.remove(first); - set.add(newFirst); - deviation = deviationFirst; - } else if (deviationLast < deviation) { - set.remove(last); - set.add(newLast); - deviation = deviationLast; - } else { - break; // done - } - - } - - return deviation; - } - - public int minimumDeviation3(int[] _nums) { - - if (_nums == null) { - return 0; - } - final int len = _nums.length; - if (len <= 1) { - return 0; - } - - // find the maximum of minimized values and - // minimum of maximized values - int rangeBgn = -1; - int rangeEnd = -1; - - for (int i = 0; i < len; i++) { - int min = _nums[i]; - int max = _nums[i]; - - if (_nums[i] % 2 == 1) { // odd - max *= 2; - } else { // even - while (min % 2 == 0) { - min /= 2; - } - } - - if (i == 0) { - rangeBgn = min; - rangeEnd = max; - } else { - - if (max < rangeBgn) { - rangeBgn = max; - } else if (min > rangeBgn) { - rangeBgn = min; - } else if (min > rangeEnd) { - rangeEnd = min; - } else if (max < rangeEnd) { - rangeEnd = max; - } - } - - } - - return Math.abs(rangeEnd - rangeBgn); - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1676.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1676.java index 0e3a3c23..7b97fb30 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1676.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1676.java @@ -9,7 +9,7 @@ class Problem1676 extends LeetcodeProblem { private TreeNode lca = null; - public TreeNode lowestCommonAncestor(TreeNode _root, TreeNode[] _nodes) { + TreeNode lowestCommonAncestor(TreeNode _root, TreeNode[] _nodes) { Set target = new HashSet<>(); for (TreeNode node : _nodes) { target.add(node.val); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1682.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1682.java index 10057e20..284a587d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1682.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1682.java @@ -12,7 +12,7 @@ class Problem1682 extends LeetcodeProblem { private int[][][] f; private String s; - public int longestPalindromeSubseq(String _s) { + int longestPalindromeSubseq(String _s) { s = _s; int len = _s.length(); f = new int[len][len][27]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1690.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1690.java index ca00fdd8..1222f5bd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1690.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1600/Problem1690.java @@ -10,7 +10,7 @@ class Problem1690 extends LeetcodeProblem { private final int[][] maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ = new int[1005][1005]; - public int stoneGameVII(int[] _stones) { + int stoneGameVII(int[] _stones) { stonesRef = _stones; int totalStonesNumber = _stones.length; prepareSums = new int[totalStonesNumber + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1704.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1704.java index 180233c7..21f2d06b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1704.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1704.java @@ -27,34 +27,4 @@ boolean halvesAreAlike(final String _str) { return count == 0; } - public boolean halvesAreAlike2(String _str) { - if (_str == null) { - return false; - } - final int len = _str.length(); - if (len % 2 != 0) { - return false; - } - String a = _str.substring(0, len / 2); - String b = _str.substring(len / 2); - - // return a.replaceAll("[^aeiouAEIOU]", "").length() == b.replaceAll("[^aeiouAEIOU]", "").length(); - return countVowels(a) == countVowels(b); - } - - static int countVowels(String _str) { - int ans = 0; - for (char c : _str.toCharArray()) { - if (isVowel(c)) { - ans++; - } - } - return ans; - } - - static boolean isVowel(char _c) { - return _c == 'a' || _c == 'e' || _c == 'i' || _c == 'o' || _c == 'u' - || _c == 'A' || _c == 'E' || _c == 'I' || _c == 'O' || _c == 'U'; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1706.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1706.java index 8c101b04..b097cba0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1706.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1706.java @@ -11,7 +11,7 @@ class Problem1706 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int[] findBall(int[][] _grid) { + int[] findBall(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1711.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1711.java index 07911c76..9822b5b3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1711.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1711.java @@ -8,7 +8,7 @@ class Problem1711 extends LeetcodeProblem { private static final long MODUALR = 1000000007; - public int countPairs(int[] _deliciousness) { + int countPairs(int[] _deliciousness) { Map map = new HashMap<>(); long pairs = 0; for (int element : _deliciousness) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1712.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1712.java index 655e7e69..3e978d91 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1712.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1712.java @@ -9,7 +9,7 @@ class Problem1712 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int waysToSplit(int[] nums) { + int waysToSplit(int[] nums) { int n = nums.length; int[] s = new int[n]; s[0] = nums[0]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1722.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1722.java index b3eeaa99..3f917eef 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1722.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1722.java @@ -12,7 +12,7 @@ class Problem1722 extends LeetcodeProblem { private int[] p; - public int minimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) { + int minimumHammingDistance(int[] source, int[] target, int[][] allowedSwaps) { int n = source.length; p = new int[n]; for (int i = 0; i < n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1723.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1723.java index 769bdbb9..ada7b576 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1723.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1723.java @@ -14,7 +14,7 @@ class Problem1723 extends LeetcodeProblem { private int[] cnt; private int ans; - public int minimumTimeRequired(int[] _jobs, int _k) { + int minimumTimeRequired(int[] _jobs, int _k) { jobs = _jobs; Arrays.sort(jobs); for (int i = 0, j = jobs.length - 1; i < j; i++, j--) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1730.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1730.java index f98995f7..e57eb812 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1730.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1730.java @@ -12,7 +12,7 @@ class Problem1730 extends LeetcodeProblem { private static final int[] DIRS = {-1, 0, 1, 0, -1}; - public int getFood(char[][] grid) { + int getFood(char[][] grid) { int m = grid.length; int n = grid[0].length; Deque q = new ArrayDeque<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1735.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1735.java index 06c9749b..c71b7ad6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1735.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1735.java @@ -42,7 +42,7 @@ class Problem1735 extends LeetcodeProblem { } } - public static long qmi(long a, long k, long p) { + static long qmi(long a, long k, long p) { long res = 1; while (k != 0) { if ((k & 1) == 1) { @@ -54,11 +54,11 @@ public static long qmi(long a, long k, long p) { return res; } - public static long comb(int n, int k) { + static long comb(int n, int k) { return F[n] * G[k] % MOD * G[n - k] % MOD; } - public int[] waysToFillArray(int[][] queries) { + int[] waysToFillArray(int[][] queries) { int m = queries.length; int[] ans = new int[m]; for (int i = 0; i < m; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1737.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1737.java index 084d58f5..e4d31210 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1737.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1737.java @@ -9,7 +9,7 @@ class Problem1737 extends LeetcodeProblem { private int ans; - public int minCharacters(String a, String b) { + int minCharacters(String a, String b) { int m = a.length(); int n = b.length(); int[] cnt1 = new int[26]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1766.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1766.java index bd9127e2..50890e71 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1766.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1766.java @@ -16,7 +16,7 @@ class Problem1766 extends LeetcodeProblem { private int[] ans; @SuppressWarnings("unchecked") - public int[] getCoprimes(int[] _nums, int[][] _edges) { + int[] getCoprimes(int[] _nums, int[][] _edges) { int n = _nums.length; g = new List[n]; Arrays.setAll(g, k -> new ArrayList<>()); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1774.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1774.java index fc6f380f..4addb140 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1774.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1774.java @@ -5,7 +5,7 @@ class Problem1774 extends LeetcodeProblem { private int result = 0; - public int closestCost(int[] _baseCosts, int[] _toppingCosts, int _target) { + int closestCost(int[] _baseCosts, int[] _toppingCosts, int _target) { result = _baseCosts[0]; for (int baseCost : _baseCosts) { recursion(baseCost, _toppingCosts, 0, _target); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1778.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1778.java index b020f0df..e26f1fd0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1778.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1778.java @@ -20,7 +20,7 @@ class Problem1778 extends LeetcodeProblem { private Set s; private int[] target; - public int findShortestPath(GridMaster _master) { + int findShortestPath(GridMaster _master) { target = null; s = new HashSet<>(); s.add(0); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1786.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1786.java index baa309ac..c92fa33d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1786.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1700/Problem1786.java @@ -16,7 +16,7 @@ class Problem1786 extends LeetcodeProblem { private int[] f; private int n; - public int countRestrictedPaths(int _n, int[][] _edges) { + int countRestrictedPaths(int _n, int[][] _edges) { n = _n; @SuppressWarnings("unchecked") List[] lists = new List[_n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1808.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1808.java index 1e572462..43bd503e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1808.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1808.java @@ -9,7 +9,7 @@ class Problem1808 extends LeetcodeProblem { private final int mod = (int) 1e9 + 7; - public int maxNiceDivisors(int primeFactors) { + int maxNiceDivisors(int primeFactors) { if (primeFactors < 4) { return primeFactors; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1810.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1810.java index d4b09d9b..f42a85d0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1810.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1810.java @@ -22,7 +22,7 @@ class Problem1810 extends LeetcodeProblem { private static final int[][] DIST = new int[N][N]; private int[] target; - public int findShortestPath(GridMaster _master) { + int findShortestPath(GridMaster _master) { target = new int[] {-1, -1}; for (int i = 0; i < N; i++) { Arrays.fill(G[i], -1); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1815.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1815.java index 6a97f677..9a01674e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1815.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1815.java @@ -13,7 +13,7 @@ class Problem1815 extends LeetcodeProblem { private final Map f = new HashMap<>(); private int size; - public int maxHappyGroups(int _batchSize, int[] _groups) { + int maxHappyGroups(int _batchSize, int[] _groups) { size = _batchSize; int ans = 0; long state = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1820.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1820.java index 100fb89e..ecd56cb3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1820.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1820.java @@ -14,7 +14,7 @@ class Problem1820 extends LeetcodeProblem { private boolean[] vis; private int[] match; - public int maximumInvitations(int[][] _grid) { + int maximumInvitations(int[][] _grid) { grid = _grid; int nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1830.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1830.java index 5ac92d2c..a20ac196 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1830.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1830.java @@ -21,7 +21,7 @@ class Problem1830 extends LeetcodeProblem { } } - public static long qmi(long a, int k) { + static long qmi(long a, int k) { long res = 1; while (k != 0) { if ((k & 1) == 1) { @@ -33,7 +33,7 @@ public static long qmi(long a, int k) { return res; } - public int makeStringSorted(String s) { + int makeStringSorted(String s) { int[] cnt = new int[26]; int n = s.length(); for (int i = 0; i < n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1849.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1849.java index b56f7ed4..075a96d5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1849.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1849.java @@ -9,7 +9,7 @@ class Problem1849 extends LeetcodeProblem { private String s; - public boolean splitString(String _s) { + boolean splitString(String _s) { s = _s; return dfs(0, -1, 0); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1858.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1858.java index 679932a8..e375e713 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1858.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1858.java @@ -22,7 +22,7 @@ String longestWord(String[] words) { return ans; } - public static class Trie { + static class Trie { private final Trie[] children = new Trie[26]; private boolean isEnd; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1863.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1863.java index 5570242d..9d8317ea 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1863.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1863.java @@ -14,19 +14,4 @@ int subsetXORSum(int[] _nums) { static int helper(int[] _nums, int _len, int idx, int _curr) { return idx == _len ? _curr : helper(_nums, _len, idx + 1, _curr ^ _nums[idx]) + helper(_nums, _len, idx + 1, _curr); } - - int subsetXORSum2(int[] _nums) { - int len = _nums.length; - int result = 0; - for (int i = 0; i < 1 << len; ++i) { - int s = 0; - for (int j = 0; j < len; ++j) { - if ((i >> j & 1) == 1) { - s ^= _nums[j]; - } - } - result += s; - } - return result; - } } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1895.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1895.java index 98ba6499..01b12119 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1895.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1800/Problem1895.java @@ -10,7 +10,7 @@ class Problem1895 extends LeetcodeProblem { private int[][] rowsum; private int[][] colsum; - public int largestMagicSquare(int[][] grid) { + int largestMagicSquare(int[][] grid) { int m = grid.length; int n = grid[0].length; rowsum = new int[m + 1][n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1905.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1905.java index 4dbc93c9..a4baaf1a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1905.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1905.java @@ -13,7 +13,7 @@ class Problem1905 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int countSubIslands(int[][] _grid1, int[][] _grid2) { + int countSubIslands(int[][] _grid1, int[][] _grid2) { nbRows = _grid1.length; nbCols = _grid1[0].length; grid1 = _grid1; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1914.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1914.java index 67b087fd..62d22e03 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1914.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1914.java @@ -14,7 +14,7 @@ class Problem1914 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int[][] rotateGrid(int[][] _grid, int _k) { + int[][] rotateGrid(int[][] _grid, int _k) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1922.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1922.java index e3f00925..8ad10b76 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1922.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1922.java @@ -9,7 +9,7 @@ class Problem1922 extends LeetcodeProblem { private static final int MOD = 1000000007; - public int countGoodNumbers(long n) { + int countGoodNumbers(long n) { return (int) (myPow(5, n + 1 >> 1) * myPow(4, n >> 1) % MOD); } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1923.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1923.java index afcb8844..d69ace73 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1923.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1923.java @@ -17,7 +17,7 @@ class Problem1923 extends LeetcodeProblem { private final Map cnt = new HashMap<>(); private final Map inner = new HashMap<>(); - public int longestCommonSubpath(int _n, int[][] _paths) { + int longestCommonSubpath(int _n, int[][] _paths) { int left = 0; int right = _n; for (int[] path : _paths) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1931.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1931.java index a61760b6..c639996a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1931.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1931.java @@ -11,10 +11,10 @@ class Problem1931 extends LeetcodeProblem { private int m; - public int colorTheGrid(int _m, int _n) { - m = _m; + int colorTheGrid(int _x, int _y) { + m = _x; final int mod = (int) 1e9 + 7; - int mx = (int) Math.pow(3, _m); + int mx = (int) Math.pow(3, _x); Set valid = new HashSet<>(); int[] f = new int[mx]; for (int i = 0; i < mx; i++) { @@ -31,7 +31,7 @@ public int colorTheGrid(int _m, int _n) { } } } - for (int k = 1; k < _n; k++) { + for (int k = 1; k < _y; k++) { int[] g = new int[mx]; for (int i : valid) { for (int j : d.getOrDefault(i, List.of())) { @@ -47,7 +47,7 @@ public int colorTheGrid(int _m, int _n) { return ans; } - private boolean f1(int x) { + boolean f1(int x) { int last = -1; for (int i = 0; i < m; i++) { if (x % 3 == last) { @@ -59,7 +59,7 @@ private boolean f1(int x) { return true; } - private boolean f2(int x, int y) { + boolean f2(int x, int y) { for (int i = 0; i < m; i++) { if (x % 3 == y % 3) { return false; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1935.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1935.java index bb5fc04d..c3931fb9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1935.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1935.java @@ -5,7 +5,7 @@ class Problem1935 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public int canBeTypedWords(String _text, String _brokenLetters) { + int canBeTypedWords(String _text, String _brokenLetters) { String[] words = _text.split(" "); int count = 0; for (String word : words) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1944.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1944.java index 42587b6e..7b5a66fa 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1944.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1944.java @@ -11,7 +11,7 @@ class Problem1944 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public int[] canSeePersonsCount(int[] _heights) { + int[] canSeePersonsCount(int[] _heights) { int nbHeights = _heights.length; int[] ans = new int[nbHeights]; Deque stk = new ArrayDeque<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1947.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1947.java index 356e9e87..7bab691f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1947.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1947.java @@ -12,7 +12,7 @@ class Problem1947 extends LeetcodeProblem { private int m; private int ans; - public int maxCompatibilitySum(int[][] students, int[][] mentors) { + int maxCompatibilitySum(int[][] students, int[][] mentors) { m = students.length; g = new int[m][m]; vis = new boolean[m]; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1958.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1958.java index edf730de..848b9fcd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1958.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1958.java @@ -10,7 +10,7 @@ class Problem1958 extends LeetcodeProblem { private static final int[][] DIRS = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; private static final int N = 8; - public boolean checkMove(char[][] board, int rMove, int cMove, char color) { + boolean checkMove(char[][] board, int rMove, int cMove, char color) { for (int[] d : DIRS) { int i = rMove; int j = cMove; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1973.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1973.java index 1a2be61d..699f5dd3 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1973.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1973.java @@ -10,7 +10,7 @@ class Problem1973 extends LeetcodeProblem { private int ans; - public int equalToDescendants(TreeNode root) { + int equalToDescendants(TreeNode root) { dfs(root); return ans; } diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1977.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1977.java index c9ed5dcb..f8eebeae 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1977.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1977.java @@ -9,7 +9,7 @@ class Problem1977 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int numberOfCombinations(String num) { + int numberOfCombinations(String num) { int n = num.length(); int[][] lcp = new int[n + 1][n + 1]; for (int i = n - 1; i >= 0; i--) { diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1981.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1981.java index 41c12fbd..6e342cc6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1981.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1981.java @@ -6,7 +6,7 @@ class Problem1981 extends LeetcodeProblem { private int ans = Integer.MAX_VALUE; private boolean[][] dp; - public int minimizeTheDifference(int[][] _mat, int _target) { + int minimizeTheDifference(int[][] _mat, int _target) { dp = new boolean[_mat.length][4900]; memo(_mat, 0, 0, _target); return ans; diff --git a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1998.java b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1998.java index 10c1d630..9f2e8339 100644 --- a/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1998.java +++ b/src/main/java/io/github/spannm/leetcode/lc1/lc1900/Problem1998.java @@ -11,7 +11,7 @@ class Problem1998 extends LeetcodeProblem { private int[] p; - public boolean gcdSort(int[] nums) { + boolean gcdSort(int[] nums) { int n = 100010; p = new int[n]; Map> f = new HashMap<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2003.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2003.java index 539ce399..bde27539 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2003.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2003.java @@ -16,7 +16,7 @@ class Problem2003 extends LeetcodeProblem { private boolean[] has; private int[] nums; - public int[] smallestMissingValueSubtree(int[] _parents, int[] _nums) { + int[] smallestMissingValueSubtree(int[] _parents, int[] _nums) { int len = _nums.length; nums = _nums; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2024.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2024.java index e4c9c3d7..e9879d28 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2024.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2024.java @@ -14,7 +14,7 @@ int maxConsecutiveAnswers(final String _answerKey, final int _k) { return Math.max(helper(_answerKey, _k, 'F'), helper(_answerKey, _k, 'T')); } - public int helper(final String _answerKey, int _k, final char _letter) { + int helper(final String _answerKey, int _k, final char _letter) { int max = 0; int count = 0; LinkedList q = new LinkedList<>(); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2049.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2049.java index d5924489..a5213fa8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2049.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2049.java @@ -16,7 +16,7 @@ class Problem2049 extends LeetcodeProblem { private long mx; private int n; - public int countHighestScoreNodes(int[] parents) { + int countHighestScoreNodes(int[] parents) { n = parents.length; @SuppressWarnings("unchecked") List[] lists = new List[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2052.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2052.java index 0a726ae8..b8f79590 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2052.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2052.java @@ -14,7 +14,7 @@ class Problem2052 extends LeetcodeProblem { private int[] s; private int n; - public int minimumCost(String sentence, int k) { + int minimumCost(String sentence, int k) { String[] words = sentence.split(" "); n = words.length; s = new int[n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2061.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2061.java index 93b2b8ce..6e8466df 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2061.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2061.java @@ -11,7 +11,7 @@ class Problem2061 extends LeetcodeProblem { private boolean[][][] vis; private int ans; - public int numberOfCleanRooms(int[][] _room) { + int numberOfCleanRooms(int[][] _room) { room = _room; vis = new boolean[_room.length][_room[0].length][4]; dfs(0, 0, 0); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2071.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2071.java index c484458f..22adf90d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2071.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2071.java @@ -17,7 +17,7 @@ class Problem2071 extends LeetcodeProblem { private int pills; private int strength; - public int maxTaskAssign(int[] _tasks, int[] _workers, int _pills, int _strength) { + int maxTaskAssign(int[] _tasks, int[] _workers, int _pills, int _strength) { Arrays.sort(_tasks); Arrays.sort(_workers); tasks = _tasks; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090.java index 51c19a70..0a21efd9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090.java @@ -9,28 +9,7 @@ */ class Problem2090 extends LeetcodeProblem { - int[] getAverages2(final int[] _nums, final int _k) { - if (_k == 0) { - return _nums; - } - - final int div = _k * 2 + 1; - final int len = _nums.length; - final int[] out = new int[len]; - Arrays.fill(out, -1); - - for (int i = _k; i < len - _k; i++) { - long sum = 0; - for (int j = i - _k; j <= i + _k; j++) { - sum += _nums[j]; - } - out[i] = (int) (sum / div); - } - - return out; - } - - public int[] getAverages(final int[] _nums, final int _k) { + int[] getAverages(final int[] _nums, final int _k) { if (_k == 0) { return _nums; } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2096.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2096.java index 8821fe5b..5e9b521e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2096.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2000/Problem2096.java @@ -14,7 +14,7 @@ class Problem2096 extends LeetcodeProblem { private Set visited; private String ans; - public String getDirections(TreeNode root, int startValue, int destValue) { + String getDirections(TreeNode root, int startValue, int destValue) { edges = new HashMap<>(); visited = new HashSet<>(); ans = null; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2123.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2123.java index 8c8d2161..118a8286 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2123.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2123.java @@ -13,7 +13,7 @@ class Problem2123 extends LeetcodeProblem { private final Set vis = new HashSet<>(); private int[] match; - public int minimumOperations(int[][] grid) { + int minimumOperations(int[][] grid) { int m = grid.length; int n = grid[0].length; for (int i = 0; i < m; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2152.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2152.java index 95a7b962..a2673d6e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2152.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2152.java @@ -11,7 +11,7 @@ class Problem2152 extends LeetcodeProblem { private int nbPoints; private int[] f; - public int minimumLines(int[][] _points) { + int minimumLines(int[][] _points) { points = _points; nbPoints = _points.length; f = new int[1 << nbPoints]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2157.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2157.java index 1269e0a5..8bbee625 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2157.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2157.java @@ -15,7 +15,7 @@ class Problem2157 extends LeetcodeProblem { private int mx; private int n; - public int[] groupStrings(String[] words) { + int[] groupStrings(String[] words) { p = new HashMap<>(); size = new HashMap<>(); n = words.length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2170.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2170.java index d8a7e25b..3d8519ac 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2170.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2170.java @@ -13,7 +13,7 @@ class Problem2170 extends LeetcodeProblem { private int[] nums; private int len; - public int minimumOperations(int[] _nums) { + int minimumOperations(int[] _nums) { nums = _nums; len = _nums.length; int ans = Integer.MAX_VALUE; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2184.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2184.java index d09c3c7b..4f244183 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2184.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2184.java @@ -18,7 +18,7 @@ class Problem2184 extends LeetcodeProblem { private final List> res = new ArrayList<>(); private final List t = new ArrayList<>(); - public int buildWall(int _height, int _width, int[] _bricks) { + int buildWall(int _height, int _width, int[] _bricks) { width = _width; bricks = _bricks; dfs(0); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2187.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2187.java index c5e930e0..0cb618a2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2187.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2187.java @@ -19,7 +19,7 @@ long minimumTimeBruteForce(int[] _time, int _totalTrips) { } } - public long minimumTime(int[] _time, int _totalTrips) { + long minimumTime(int[] _time, int _totalTrips) { if (_time.length == 1) { return _time[0] * (long) _totalTrips; } @@ -43,7 +43,7 @@ public long minimumTime(int[] _time, int _totalTrips) { return low; } - public boolean isValidTime(long _timeToCheck, int _totalTrips, int[] _times) { + boolean isValidTime(long _timeToCheck, int _totalTrips, int[] _times) { long trips = 0; for (int time : _times) { trips += _timeToCheck / time; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2189.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2189.java index 74bd9165..c7d6250d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2189.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2100/Problem2189.java @@ -9,7 +9,7 @@ class Problem2189 extends LeetcodeProblem { private Integer[][] f; - public int houseOfCards(int n) { + int houseOfCards(int n) { f = new Integer[n + 1][n / 3]; return dfs(n, 0); } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2203.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2203.java index 58cb4294..7d0f28aa 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2203.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2203.java @@ -12,7 +12,7 @@ class Problem2203 extends LeetcodeProblem { private static final Long INF = Long.MAX_VALUE; - public long minimumWeight(int n, int[][] edges, int src1, int src2, int dest) { + long minimumWeight(int n, int[][] edges, int src1, int src2, int dest) { @SuppressWarnings("unchecked") List>[] g = new List[n]; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2209.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2209.java index 97cbc706..96dda616 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2209.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2209.java @@ -14,7 +14,7 @@ class Problem2209 extends LeetcodeProblem { private int n; private int k; - public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) { + int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) { n = floor.length(); f = new int[n][numCarpets + 1]; for (var e : f) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2233.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2233.java index 95f4a0ae..c3d0e5d1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2233.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2233.java @@ -12,7 +12,7 @@ class Problem2233 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int maximumProduct(int[] nums, int k) { + int maximumProduct(int[] nums, int k) { Queue q = new PriorityQueue<>(); for (int v : nums) { q.offer(v); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2244.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2244.java index 6a9ffc26..a6716158 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2244.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2244.java @@ -45,36 +45,4 @@ int minimumRounds(int... _tasks) { return rounds; } - int minimumRounds2(int... _tasks) { - Map taskCounts = Arrays.stream(_tasks).boxed().collect(Collectors.groupingBy(Function.identity(), TreeMap::new, Collectors.summingInt(s -> 1))); - - if (taskCounts.containsValue(1)) { - return -1; - } - int rounds = 0; - for (Map.Entry e : taskCounts.entrySet()) { - int count = e.getValue(); - int diffRounds = 0; - - // treat counts of 2 or 3 tasks equaling one round - if (count == 2 || count == 3) { - diffRounds = 1; - } else { - // 4 and more tasks - int mod3 = count % 3; - diffRounds = switch (mod3) { - case 0 -> count / 3; // 3 tasks each round - case 1 -> count / 3 - 1 + 2; // 3 tasks all except 2 tasks twice - default -> count / 3 + 1; // 3 tasks all except 2 tasks once - }; - } - - if (diffRounds == -1) { - return -1; - } - rounds += diffRounds; - } - return rounds; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2246.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2246.java index d1ab1d58..161e94fb 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2246.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2246.java @@ -15,7 +15,7 @@ class Problem2246 extends LeetcodeProblem { private String s; private int ans; - public int longestPath(int[] _parent, String _s) { + int longestPath(int[] _parent, String _s) { s = _s; int n = _parent.length; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2248.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2248.java index 7d392cfa..7a568a91 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2248.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2248.java @@ -23,7 +23,7 @@ List intersection(int[][] _nums) { return list; } - public int[] intersection(int[] _nums1, int[] _nums2) { + int[] intersection(int[] _nums1, int[] _nums2) { Set set1 = Arrays.stream(_nums1).boxed().collect(Collectors.toSet()); Set set2 = Arrays.stream(_nums2).boxed().collect(Collectors.toSet()); set1.retainAll(set2); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2258.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2258.java index e0a4ea6d..64d417a7 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2258.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2258.java @@ -18,7 +18,7 @@ class Problem2258 extends LeetcodeProblem { private boolean[][] vis; private final int[] dirs = {-1, 0, 1, 0, -1}; - public int maximumMinutes(int[][] _grid) { + int maximumMinutes(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2266.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2266.java index 26f57b4c..43263ccc 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2266.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2266.java @@ -26,7 +26,7 @@ class Problem2266 extends LeetcodeProblem { } } - public int countTexts(String pressedKeys) { + int countTexts(String pressedKeys) { long ans = 1; for (int i = 0, n = pressedKeys.length(); i < n; i++) { int j = i; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2267.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2267.java index 3d81ebaf..c1461385 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2267.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2200/Problem2267.java @@ -12,7 +12,7 @@ class Problem2267 extends LeetcodeProblem { private int nbCols; private boolean[][][] vis; - public boolean hasValidPath(char[][] _grid) { + boolean hasValidPath(char[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2307.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2307.java index f65e41ca..f2be9a84 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2307.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2307.java @@ -14,7 +14,7 @@ class Problem2307 extends LeetcodeProblem { private int[] p; private double[] w; - public boolean checkContradictions(List> equations, double[] values) { + boolean checkContradictions(List> equations, double[] values) { Map d = new HashMap<>(); int n = 0; for (var e : equations) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2312.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2312.java index 2096e571..ff8cb351 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2312.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2312.java @@ -12,7 +12,7 @@ class Problem2312 extends LeetcodeProblem { private long[][] memo; private int[][] d; - public long sellingWood(int m, int n, int[][] prices) { + long sellingWood(int m, int n, int[][] prices) { d = new int[m + 1][n + 1]; memo = new long[m + 1][n + 1]; for (long[] e : memo) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2322.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2322.java deleted file mode 100644 index be2ea29d..00000000 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2322.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.spannm.leetcode.lc2.lc2300; - -import io.github.spannm.leetcode.LeetcodeProblem; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 2322. Minimum Score After Removals on a Tree. - */ -class Problem2322 extends LeetcodeProblem { - - private int s; - private int s1; - private int ans = Integer.MAX_VALUE; - private int[] nums; - private List[] g; - - public int minimumScore(int[] _nums, int[][] _edges) { - int n = _nums.length; - @SuppressWarnings("unchecked") - List[] lists = new List[n]; - g = lists; - nums = _nums; - Arrays.setAll(g, k -> new ArrayList<>()); - for (int[] e : _edges) { - int a = e[0]; - int b = e[1]; - g[a].add(b); - g[b].add(a); - } - for (int v : _nums) { - s ^= v; - } - for (int i = 0; i < n; i++) { - for (int j : g[i]) { - s1 = dfs(i, -1, j); - dfs2(i, -1, j); - } - } - return ans; - } - - int dfs(int i, int fa, int x) { - int res = nums[i]; - for (int j : g[i]) { - if (j != fa && j != x) { - res ^= dfs(j, i, x); - } - } - return res; - } - - private int dfs2(int i, int fa, int x) { - int res = nums[i]; - for (int j : g[i]) { - if (j != fa && j != x) { - int a = dfs2(j, i, x); - res ^= a; - int b = s1 ^ a; - int c = s ^ s1; - int t = Math.max(Math.max(a, b), c) - Math.min(Math.min(a, b), c); - ans = Math.min(ans, t); - } - } - return res; - } - -} diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2327.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2327.java index 202514dd..3066017a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2327.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2327.java @@ -9,7 +9,7 @@ class Problem2327 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int peopleAwareOfSecret(int n, int delay, int forget) { + int peopleAwareOfSecret(int n, int delay, int forget) { int m = (n << 1) + 10; long[] d = new long[m]; long[] cnt = new long[m]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2328.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2328.java index cdef1759..3c95afeb 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2328.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2328.java @@ -12,7 +12,7 @@ class Problem2328 extends LeetcodeProblem { static final int MOD = (int) Math.pow(10, 9) + 7; - public static int countPaths(final int[][] _grid) { + static int countPaths(final int[][] _grid) { final int rowCount = _grid.length; final int colCount = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2338.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2338.java index d3e7e9f0..9bbfc398 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2338.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2338.java @@ -15,7 +15,7 @@ class Problem2338 extends LeetcodeProblem { private int n; private int m; - public int idealArrays(int _n, int _maxValue) { + int idealArrays(int _n, int _maxValue) { n = _n; m = _maxValue; f = new int[_maxValue + 1][16]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2359.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2359.java index 41a9477b..a401a0df 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2359.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2359.java @@ -12,7 +12,7 @@ class Problem2359 extends LeetcodeProblem { private int n; private List> lol; - public int closestMeetingNode(int[] _edges, int _node1, int _node2) { + int closestMeetingNode(int[] _edges, int _node1, int _node2) { n = _edges.length; lol = new ArrayList<>(n); for (int i = 0; i < n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2368.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2368.java index 0e23bc18..23247da6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2368.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2368.java @@ -15,7 +15,7 @@ class Problem2368 extends LeetcodeProblem { private boolean[] vis; private int ans; - public int reachableNodes(int _n, int[][] _edges, int[] _restricted) { + int reachableNodes(int _n, int[][] _edges, int[] _restricted) { @SuppressWarnings({"unchecked"}) List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2375.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2375.java index 1606b9d8..b5217acd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2375.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2375.java @@ -12,7 +12,7 @@ class Problem2375 extends LeetcodeProblem { private String p; private String ans; - public String smallestNumber(String pattern) { + String smallestNumber(String pattern) { p = pattern; dfs(0); return ans; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2378.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2378.java index f3b0189c..c6fd1879 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2378.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2378.java @@ -13,7 +13,7 @@ class Problem2378 extends LeetcodeProblem { private List[] g; - public long maxScore(int[][] _edges) { + long maxScore(int[][] _edges) { int len = _edges.length; @SuppressWarnings("unchecked") List[] lists = new List[len]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2382.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2382.java index 54fb0412..ee4d108f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2382.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2382.java @@ -10,7 +10,7 @@ class Problem2382 extends LeetcodeProblem { private int[] p; private long[] s; - public long[] maximumSegmentSum(int[] nums, int[] removeQueries) { + long[] maximumSegmentSum(int[] nums, int[] removeQueries) { int n = nums.length; p = new int[n]; s = new long[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2387.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2387.java index 172c8109..d79d6724 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2387.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2387.java @@ -9,7 +9,7 @@ class Problem2387 extends LeetcodeProblem { private int[][] grid; - public int matrixMedian(int[][] _grid) { + int matrixMedian(int[][] _grid) { grid = _grid; int nbRows = _grid.length; int nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2390.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2390.java index d79663d2..bbae28fd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2390.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2390.java @@ -23,62 +23,4 @@ String removeStars(final String _s) { return sb.toString(); } - public String removeStars1(String _s) { - if (_s != null && !_s.isEmpty()) { - java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("([^\\*]\\*)"); - java.util.regex.Matcher matcher = pattern.matcher(_s); - while (matcher.find()) { - _s = _s.replace(matcher.group(1), ""); - matcher = pattern.matcher(_s); - } - } - return _s; - } - - public String removeStars2(final String _s) { - if (_s == null || _s.isEmpty()) { - return _s; - } - - java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(\\*+)"); - java.util.regex.Matcher matcher = pattern.matcher(_s); - String newStr = _s; - while (matcher.find()) { - String stars = matcher.group(1); - int idx = newStr.indexOf(stars); - newStr = newStr.substring(0, idx - stars.length()) - + newStr.substring(idx + stars.length()); - matcher = pattern.matcher(newStr); - } - return newStr; - } - - public String removeStars3(final String _s) { - if (_s == null || _s.isEmpty() || _s.indexOf('*') < 0) { - return _s; - } - - String newStr = _s; - - for (int len = 3; len > 0; len--) { - newStr = newStr.replaceAll("[^\\*]{" + len + "}\\*{" + len + "}", ""); - if (newStr.indexOf('*') < 0) { - return newStr; - } - } - - java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(\\*+)"); - java.util.regex.Matcher matcher = pattern.matcher(_s); - - while (matcher.find()) { - String stars = matcher.group(1); - int idx = newStr.indexOf(stars); - int starsLen = stars.length(); - newStr = newStr.substring(0, idx - starsLen) - + newStr.substring(idx + starsLen); - matcher = pattern.matcher(newStr); - } - return newStr; - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2392.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2392.java index 84b5d290..4ad7f845 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2392.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2300/Problem2392.java @@ -11,7 +11,7 @@ class Problem2392 extends LeetcodeProblem { private int k; - public int[][] buildMatrix(int _k, int[][] _rowConditions, int[][] _colConditions) { + int[][] buildMatrix(int _k, int[][] _rowConditions, int[][] _colConditions) { k = _k; List row = f(_rowConditions); List col = f(_colConditions); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2400.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2400.java index 803b1943..206d2c08 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2400.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2400.java @@ -10,7 +10,7 @@ class Problem2400 extends LeetcodeProblem { private Integer[][] f; private final int mod = (int) 1e9 + 7; - public int numberOfWays(int startPos, int endPos, int k) { + int numberOfWays(int startPos, int endPos, int k) { f = new Integer[k + 1][k + 1]; return dfs(Math.abs(startPos - endPos), k); } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2403.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2403.java index 582ba84a..9bd49e4e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2403.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2403.java @@ -13,7 +13,7 @@ class Problem2403 extends LeetcodeProblem { private long[] f; private int[] power; - public long minimumTime(int[] _power) { + long minimumTime(int[] _power) { power = _power; len = _power.length; f = new long[1 << len]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2405.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2405.java index 71d88858..2da604a1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2405.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2405.java @@ -2,15 +2,12 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.HashMap; -import java.util.Map; - /** * 2405. Optimal Partition of String. */ class Problem2405 extends LeetcodeProblem { - int partitionString1(String _str) { + int partitionString(String _str) { int i = 0; int ans = 1; int flag = 0; @@ -26,19 +23,4 @@ int partitionString1(String _str) { return ans; } - public int partitionString2(String _str) { - int count = 0; - int idx = 0; - Map map = new HashMap<>(); // use a HashMap instead of an unordered_map - while (idx < _str.length()) { - if (map.containsKey(_str.charAt(idx))) { // if current character has already appeared in current substring - count++; // increment count - map.clear(); // clear map to start a new substring - } - map.put(_str.charAt(idx), true); // mark current character as seen - idx++; // move to next character - } - return count + 1; // return number of substrings (add 1 because we need to count the last substring as well) - } - } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2409.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2409.java index 45698eb2..4298a0a7 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2409.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2409.java @@ -9,7 +9,7 @@ class Problem2409 extends LeetcodeProblem { private static final int[] DAYS = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - public int countDaysTogether( + int countDaysTogether( String arriveAlice, String leaveAlice, String arriveBob, String leaveBob) { String a = arriveAlice.compareTo(arriveBob) < 0 ? arriveBob : arriveAlice; String b = leaveAlice.compareTo(leaveBob) < 0 ? leaveAlice : leaveBob; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2416.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2416.java index 543e17d6..91479db0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2416.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2416.java @@ -19,7 +19,7 @@ int[] sumPrefixScores(String[] words) { return ans; } - public static class Trie { + static class Trie { private final Trie[] children = new Trie[26]; private int cnt; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2421.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2421.java index d08d86d1..3cae6851 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2421.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2421.java @@ -11,7 +11,7 @@ class Problem2421 extends LeetcodeProblem { private int[] p; - public int numberOfGoodPaths(int[] _vals, int[][] _edges) { + int numberOfGoodPaths(int[] _vals, int[][] _edges) { int n = _vals.length; p = new int[n]; int[][] arr = new int[n][2]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2431.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2431.java index 6b063ba9..8ad95f2b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2431.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2431.java @@ -12,7 +12,7 @@ class Problem2431 extends LeetcodeProblem { private int[] tastiness; private int[][][] f; - public int maxTastiness(int[] _price, int[] _tastiness, int _maxAmount, int _maxCoupons) { + int maxTastiness(int[] _price, int[] _tastiness, int _maxAmount, int _maxCoupons) { price = _price; n = _price.length; tastiness = _tastiness; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2435.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2435.java index e159083e..95085f25 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2435.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2435.java @@ -9,7 +9,7 @@ class Problem2435 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int numberOfPaths(int[][] grid, int k) { + int numberOfPaths(int[][] grid, int k) { int m = grid.length; int n = grid[0].length; int[][][] dp = new int[m][n][k]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2438.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2438.java index f2c716d7..13d448f5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2438.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2438.java @@ -9,7 +9,7 @@ class Problem2438 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int[] productQueries(int n, int[][] queries) { + int[] productQueries(int n, int[][] queries) { int[] powers = new int[Integer.bitCount(n)]; for (int i = 0; n > 0; i++) { int x = n & -n; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2440.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2440.java index 3610daf9..2a91f1b4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2440.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2440.java @@ -15,7 +15,7 @@ class Problem2440 extends LeetcodeProblem { private int[] nums; private int t; - public int componentValue(int[] _nums, int[][] _edges) { + int componentValue(int[] _nums, int[][] _edges) { int n = _nums.length; @SuppressWarnings("unchecked") List[] lists = new List[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2445.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2445.java index 74a0212e..4566069d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2445.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2445.java @@ -9,7 +9,7 @@ class Problem2445 extends LeetcodeProblem { private int[] tree; - public int numberOfNodes(int n, int[] queries) { + int numberOfNodes(int n, int[] queries) { tree = new int[n + 1]; int[] cnt = new int[n + 1]; for (int v : queries) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2450.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2450.java index a8084cb0..0b836e37 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2450.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2450.java @@ -9,7 +9,7 @@ class Problem2450 extends LeetcodeProblem { static final int MOD = (int) 1e9 + 7; - public int countDistinctStrings(String s, int k) { + int countDistinctStrings(String s, int k) { int ans = 1; for (int i = 0; i < s.length() - k + 1; i++) { ans = ans * 2 % MOD; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2458.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2458.java index 81041232..896b5bdd 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2458.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2458.java @@ -14,7 +14,7 @@ class Problem2458 extends LeetcodeProblem { private final Map d = new HashMap<>(); private int[] res; - public int[] treeQueries(TreeNode root, int[] queries) { + int[] treeQueries(TreeNode root, int[] queries) { f(root); res = new int[d.size() + 1]; d.put(null, 0); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2463.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2463.java index e9612f0a..c39f82c2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2463.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2463.java @@ -16,7 +16,7 @@ class Problem2463 extends LeetcodeProblem { private int[][] factory; private long[][] f; - public long minimumTotalDistance(List _robot, int[][] _factory) { + long minimumTotalDistance(List _robot, int[][] _factory) { robot = _robot; factory = _factory; Collections.sort(_robot); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2464.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2464.java index 35387839..21cfebf9 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2464.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2464.java @@ -12,7 +12,7 @@ class Problem2464 extends LeetcodeProblem { private int n; private int[] f; - public int validSubarraySplit(int[] _nums) { + int validSubarraySplit(int[] _nums) { nums = _nums; n = _nums.length; f = new int[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2467.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2467.java index 94c2224b..e92cfe8c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2467.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2467.java @@ -16,7 +16,7 @@ class Problem2467 extends LeetcodeProblem { private int[] ts; private int ans = Integer.MIN_VALUE; - public int mostProfitablePath(int[][] _edges, int _bob, int[] _amount) { + int mostProfitablePath(int[][] _edges, int _bob, int[] _amount) { int n = _edges.length + 1; @SuppressWarnings("unchecked") List[] lists = new List[n]; @@ -37,7 +37,7 @@ public int mostProfitablePath(int[][] _edges, int _bob, int[] _amount) { return ans; } - private boolean dfs1(int _i, int _fa, int _t) { + boolean dfs1(int _i, int _fa, int _t) { if (_i == 0) { ts[_i] = Math.min(ts[_i], _t); return true; @@ -51,7 +51,7 @@ private boolean dfs1(int _i, int _fa, int _t) { return false; } - private void dfs2(int _i, int _fa, int _t, int _v) { + void dfs2(int _i, int _fa, int _t, int _v) { if (_t == ts[_i]) { _v += amount[_i] >> 1; } else if (_t < ts[_i]) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2472.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2472.java index 2e05a734..695fa69f 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2472.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2472.java @@ -14,7 +14,7 @@ class Problem2472 extends LeetcodeProblem { private int n; private int k; - public int maxPalindromes(String _s, int _k) { + int maxPalindromes(String _s, int _k) { n = _s.length(); f = new int[n]; k = _k; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2473.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2473.java index 45e33c51..c5207ea1 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2473.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2473.java @@ -15,7 +15,7 @@ class Problem2473 extends LeetcodeProblem { private int[] dist; private List[] g; - public long[] minCost(int _n, int[][] _roads, int[] _appleCost, int _k) { + long[] minCost(int _n, int[][] _roads, int[] _appleCost, int _k) { cost = _appleCost; @SuppressWarnings("unchecked") List[] lists = new List[_n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2476.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2476.java index 719e790b..ab4984c2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2476.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2476.java @@ -14,7 +14,7 @@ class Problem2476 extends LeetcodeProblem { private final List nums = new ArrayList<>(); - public List> closestNodes(TreeNode _root, List _queries) { + List> closestNodes(TreeNode _root, List _queries) { dfs(_root); List> ans = new ArrayList<>(); for (int x : _queries) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2477.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2477.java index 62705e1a..5b6ad8f8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2477.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2477.java @@ -15,7 +15,7 @@ class Problem2477 extends LeetcodeProblem { private int seats; private long ans; - public long minimumFuelCost(int[][] _roads, int _seats) { + long minimumFuelCost(int[][] _roads, int _seats) { int n = _roads.length + 1; @SuppressWarnings("unchecked") List[] lists = new List[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2478.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2478.java index c89d783d..92ea618d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2478.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2478.java @@ -9,7 +9,7 @@ class Problem2478 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int beautifulPartitions(String s, int k, int minLength) { + int beautifulPartitions(String s, int k, int minLength) { int n = s.length(); if (!prime(s.charAt(0)) || prime(s.charAt(n - 1))) { return 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2479.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2479.java index 56ff1c51..54add79d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2479.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2479.java @@ -17,7 +17,7 @@ class Problem2479 extends LeetcodeProblem { private Trie tree; private long ans; - public long maxXor(int _n, int[][] _edges, int[] _values) { + long maxXor(int _n, int[][] _edges, int[] _values) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; @@ -36,7 +36,7 @@ public long maxXor(int _n, int[][] _edges, int[] _values) { return ans; } - private void dfs2(int i, int fa) { + void dfs2(int i, int fa) { ans = Math.max(ans, tree.search(s[i])); for (int j : g[i]) { if (j != fa) { @@ -46,7 +46,7 @@ private void dfs2(int i, int fa) { tree.insert(s[i]); } - private long dfs1(int i, int fa) { + long dfs1(int i, int fa) { long t = vals[i]; for (int j : g[i]) { if (j != fa) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2484.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2484.java index e21cee8c..e1117896 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2484.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2484.java @@ -9,7 +9,7 @@ class Problem2484 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int countPalindromes(String s) { + int countPalindromes(String s) { int n = s.length(); int[][][] pre = new int[n + 2][10][10]; int[][][] suf = new int[n + 2][10][10]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2493.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2493.java index b828e5ad..4fc4d9e4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2493.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2400/Problem2493.java @@ -14,7 +14,7 @@ class Problem2493 extends LeetcodeProblem { private boolean[] vis; private int n; - public int magnificentSets(int _n, int[][] _edges) { + int magnificentSets(int _n, int[][] _edges) { @SuppressWarnings("unchecked") List[] lists = new List[_n + 1]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2510.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2510.java index cbfeb664..918b4427 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2510.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2510.java @@ -13,7 +13,7 @@ class Problem2510 extends LeetcodeProblem { private int s; private Boolean[][][] f; - public boolean isThereAPath(int[][] _grid) { + boolean isThereAPath(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2514.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2514.java index bc1609fe..ce9173b5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2514.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2514.java @@ -11,7 +11,7 @@ class Problem2514 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int countAnagrams(String s) { + int countAnagrams(String s) { int n = s.length(); long[] f = new long[n + 1]; f[0] = 1; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2518.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2518.java index 211b55df..4af058f8 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2518.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2518.java @@ -9,7 +9,7 @@ class Problem2518 extends LeetcodeProblem { private static final int MOD = (int) 1e9 + 7; - public int countPartitions(int[] nums, int k) { + int countPartitions(int[] nums, int k) { long s = 0; for (int v : nums) { s += v; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2522.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2522.java index 84939631..1ad7b794 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2522.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2522.java @@ -14,7 +14,7 @@ class Problem2522 extends LeetcodeProblem { private int n; private Integer[] f; - public int minimumPartition(String _s, int _k) { + int minimumPartition(String _s, int _k) { s = _s; k = _k; n = _s.length(); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2524.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2524.java index 4463eb33..ac893dce 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2524.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2524.java @@ -12,7 +12,7 @@ class Problem2524 extends LeetcodeProblem { private final int mod = (int) 1e9 + 7; - public int maxFrequencyScore(int[] nums, int k) { + int maxFrequencyScore(int[] nums, int k) { Map cnt = new HashMap<>(); for (int i = 0; i < k; i++) { cnt.merge(nums[i], 1, Integer::sum); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2528.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2528.java index 13927906..239facac 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2528.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2528.java @@ -13,7 +13,7 @@ class Problem2528 extends LeetcodeProblem { private long[] d; private int n; - public long maxPower(int[] stations, int r, int k) { + long maxPower(int[] stations, int r, int k) { n = stations.length; d = new long[n + 1]; s = new long[n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2538.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2538.java index c988e14a..4a66d144 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2538.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2538.java @@ -15,7 +15,7 @@ class Problem2538 extends LeetcodeProblem { private long ans; private int[] price; - public long maxOutput(int _n, int[][] _edges, int[] _price) { + long maxOutput(int _n, int[][] _edges, int[] _price) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2539.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2539.java index 48fa9074..36116d8e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2539.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2539.java @@ -21,7 +21,7 @@ class Problem2539 extends LeetcodeProblem { } } - public static long qmi(long a, long k, long p) { + static long qmi(long a, long k, long p) { long res = 1; while (k != 0) { if ((k & 1) == 1) { @@ -33,11 +33,11 @@ public static long qmi(long a, long k, long p) { return res; } - public static long comb(int n, int k) { + static long comb(int n, int k) { return F[n] * G[k] % MOD * G[n - k] % MOD; } - public int countGoodSubsequences(String s) { + int countGoodSubsequences(String s) { int[] cnt = new int[26]; int mx = 1; for (int i = 0; i < s.length(); i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2547.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2547.java index 99196093..1913ab66 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2547.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2547.java @@ -12,7 +12,7 @@ class Problem2547 extends LeetcodeProblem { private int k; private Integer[] f; - public int minCost(int[] _nums, int _k) { + int minCost(int[] _nums, int _k) { nums = _nums; n = _nums.length; k = _k; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2553.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2553.java index 98c6fa2e..2d44c505 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2553.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2553.java @@ -2,31 +2,12 @@ import io.github.spannm.leetcode.LeetcodeProblem; -import java.util.Arrays; -import java.util.stream.Collectors; - /** * 2553. Separate the Digits in an Array. */ class Problem2553 extends LeetcodeProblem { int[] separateDigits(int[] _nums) { - return separateDigits2(_nums); - } - - public int[] separateDigits1(int[] _nums) { - String str = Arrays.stream(_nums).mapToObj(Integer::toString).collect(Collectors.joining()); - - final int len = str.length(); - final int[] digits = new int[len]; - - for (int i = 0; i < len; i++) { - digits[i] = Integer.parseInt(str.substring(i, i + 1)); - } - return digits; - } - - public int[] separateDigits2(int[] _nums) { int n = 0; for (int num : _nums) { while (num > 0) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2556.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2556.java index 16b1e71c..074c83d2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2556.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2556.java @@ -11,7 +11,7 @@ class Problem2556 extends LeetcodeProblem { private int nbRows; private int nbCols; - public boolean isPossibleToCutPath(int[][] _grid) { + boolean isPossibleToCutPath(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2565.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2565.java index c202e1bb..c993146e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2565.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2565.java @@ -12,7 +12,7 @@ class Problem2565 extends LeetcodeProblem { private int[] f; private int[] g; - public int minimumScore(String s, String t) { + int minimumScore(String s, String t) { m = s.length(); n = t.length(); f = new int[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2581.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2581.java index 7fc4a9fc..46c99437 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2581.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2500/Problem2581.java @@ -16,7 +16,7 @@ class Problem2581 extends LeetcodeProblem { private int cnt; private int n; - public int rootCount(int[][] _edges, int[][] _guesses, int _k) { + int rootCount(int[][] _edges, int[][] _guesses, int _k) { k = _k; n = _edges.length + 1; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2604.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2604.java index 3fa90522..d9eac389 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2604.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2604.java @@ -13,7 +13,7 @@ class Problem2604 extends LeetcodeProblem { private int[] grains; private int len; - public int minimumTime(int[] _hens, int[] _grains) { + int minimumTime(int[] _hens, int[] _grains) { hens = _hens; grains = _grains; len = _grains.length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2608.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2608.java index 237a10eb..faa8223e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2608.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2608.java @@ -12,7 +12,7 @@ class Problem2608 extends LeetcodeProblem { private List[] g; private final int inf = 1 << 30; - public int findShortestCycle(int n, int[][] edges) { + int findShortestCycle(int n, int[][] edges) { @SuppressWarnings("unchecked") List[] lists = new List[n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2613.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2613.java index ca029c09..69c38465 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2613.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2613.java @@ -11,7 +11,7 @@ class Problem2613 extends LeetcodeProblem { private final List points = new ArrayList<>(); - public int[] beautifulPair(int[] nums1, int[] nums2) { + int[] beautifulPair(int[] nums1, int[] nums2) { int n = nums1.length; Map> pl = new HashMap<>(); for (int i = 0; i < n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2641.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2641.java index c5713a25..a173d202 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2641.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2641.java @@ -13,7 +13,7 @@ class Problem2641 extends LeetcodeProblem { private final List s = new ArrayList<>(); - public TreeNode replaceValueInTree(TreeNode root) { + TreeNode replaceValueInTree(TreeNode root) { dfs1(root, 0); root.val = 0; dfs2(root, 1); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2646.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2646.java index e209619a..57c5a047 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2646.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2646.java @@ -15,7 +15,7 @@ class Problem2646 extends LeetcodeProblem { private int[] price; private int[] cnt; - public int minimumTotalPrice(int _n, int[][] _edges, int[] _price, int[][] _trips) { + int minimumTotalPrice(int _n, int[][] _edges, int[] _price, int[][] _trips) { price = _price; cnt = new int[_n]; @SuppressWarnings("unchecked") diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2658.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2658.java index 0ee00a06..cb3656c5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2658.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2658.java @@ -11,7 +11,7 @@ class Problem2658 extends LeetcodeProblem { private int nbRows; private int nbCols; - public int findMaxFish(int[][] _grid) { + int findMaxFish(int[][] _grid) { grid = _grid; nbRows = _grid.length; nbCols = _grid[0].length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2660.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2660.java index 7ba1ef98..83f58c3b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2660.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2660.java @@ -8,7 +8,7 @@ class Problem2660 extends LeetcodeProblem { @SuppressWarnings("PMD.LinguisticNaming") - public int isWinner(int[] _player1, int[] _player2) { + int isWinner(int[] _player1, int[] _player2) { int a = f(_player1); int b = f(_player2); return a > b ? 1 : b > a ? 2 : 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2663.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2663.java index 2ae51ab8..6049cb58 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2663.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2663.java @@ -8,7 +8,7 @@ class Problem2663 extends LeetcodeProblem { @SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop") - public String smallestBeautifulString(String _s, int _k) { + String smallestBeautifulString(String _s, int _k) { int n = _s.length(); char[] cs = _s.toCharArray(); for (int i = n - 1; i >= 0; i--) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2664.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2664.java index 6f8ce2ed..0be40f0d 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2664.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2664.java @@ -14,7 +14,7 @@ class Problem2664 extends LeetcodeProblem { private int[][] g; private boolean ok; - public int[][] tourOfKnight(int _m, int _n, int _r, int _c) { + int[][] tourOfKnight(int _m, int _n, int _r, int _c) { m = _m; n = _n; g = new int[_m][_n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2673.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2673.java index 09a4fdb1..3fa24267 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2673.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2673.java @@ -11,7 +11,7 @@ class Problem2673 extends LeetcodeProblem { private int n; private int ans; - public int minIncrements(int _n, int[] _cost) { + int minIncrements(int _n, int[] _cost) { n = _n; cost = _cost; dfs(1); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2685.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2685.java index baf99103..a3055bae 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2685.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2685.java @@ -14,7 +14,7 @@ class Problem2685 extends LeetcodeProblem { private List[] g; private boolean[] vis; - public int countCompleteComponents(int _n, int[][] _edges) { + int countCompleteComponents(int _n, int[][] _edges) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2699.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2699.java index 216812fa..447e1a08 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2699.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2600/Problem2699.java @@ -11,7 +11,7 @@ class Problem2699 extends LeetcodeProblem { private final int inf = 2000000000; - public int[][] modifiedGraphEdges( + int[][] modifiedGraphEdges( int n, int[][] edges, int source, int destination, int target) { long d = dijkstra(edges, n, source, destination); if (d < target) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2702.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2702.java index d87fed94..2ab6be65 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2702.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2702.java @@ -11,7 +11,7 @@ class Problem2702 extends LeetcodeProblem { private int x; private int y; - public int minOperations(int[] _nums, int _x, int _y) { + int minOperations(int[] _nums, int _x, int _y) { nums = _nums; x = _x; y = _y; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2719.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2719.java index 75fc1946..c85639df 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2719.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2719.java @@ -15,7 +15,7 @@ class Problem2719 extends LeetcodeProblem { private int max; private Integer[][] f; - public int count(String _num1, String _num2, int _minSum, int _maxSum) { + int count(String _num1, String _num2, int _minSum, int _maxSum) { min = _minSum; max = _maxSum; num = _num2; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2746.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2746.java index 87ec4d49..73d6ea62 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2746.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2746.java @@ -11,7 +11,7 @@ class Problem2746 extends LeetcodeProblem { private int n; private Integer[][][] f; - public int minimizeConcatenatedLength(String[] _words) { + int minimizeConcatenatedLength(String[] _words) { words = _words; n = _words.length; f = new Integer[n][26][26]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2764.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2764.java index dd6eda0d..a8c53cd6 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2764.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2764.java @@ -16,7 +16,7 @@ class Problem2764 extends LeetcodeProblem { private final Map> g = new HashMap<>(); private int k; - public boolean isPreorder(List> _nodes) { + boolean isPreorder(List> _nodes) { nodes = _nodes; for (var node : _nodes) { g.computeIfAbsent(node.get(1), key -> new ArrayList<>()).add(node.get(0)); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2767.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2767.java index 70f958ec..94b966c4 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2767.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2767.java @@ -15,7 +15,7 @@ class Problem2767 extends LeetcodeProblem { private final Set ss = new HashSet<>(); private int n; - public int minimumBeautifulSubstrings(String _s) { + int minimumBeautifulSubstrings(String _s) { s = _s; n = _s.length(); f = new Integer[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2770.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2770.java index e9fa1297..05607e0b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2770.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2770.java @@ -12,7 +12,7 @@ class Problem2770 extends LeetcodeProblem { private int target; private Integer[] f; - public int maximumJumps(int[] _nums, int _target) { + int maximumJumps(int[] _nums, int _target) { nums = _nums; len = _nums.length; target = _target; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2773.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2773.java index 3278c68d..5f5c0d89 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2773.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2773.java @@ -10,7 +10,7 @@ class Problem2773 extends LeetcodeProblem { private int ans; - public int heightOfTree(TreeNode root) { + int heightOfTree(TreeNode root) { dfs(root, 0); return ans; } diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2791.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2791.java index e8432244..1b75de47 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2791.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2791.java @@ -13,7 +13,7 @@ class Problem2791 extends LeetcodeProblem { private final Map cnt = new HashMap<>(); private long ans; - public long countPalindromePaths(List parent, String s) { + long countPalindromePaths(List parent, String s) { int n = parent.size(); @SuppressWarnings("unchecked") List[] lists = new List[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2792.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2792.java index 5ec0f8ea..1af857b0 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2792.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2700/Problem2792.java @@ -14,7 +14,7 @@ class Problem2792 extends LeetcodeProblem { private int k; private int ans; - public int countGreatEnoughNodes(TreeNode _root, int _k) { + int countGreatEnoughNodes(TreeNode _root, int _k) { k = _k; dfs(_root); return ans; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2801.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2801.java index e2b87ae1..95c5be5a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2801.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2801.java @@ -13,7 +13,7 @@ class Problem2801 extends LeetcodeProblem { private String num; private Integer[][] f; - public int countSteppingNumbers(String low, String high) { + int countSteppingNumbers(String low, String high) { f = new Integer[high.length() + 1][10]; num = high; int a = dfs(0, -1, true, true); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2811.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2811.java index d0cc7294..f048c898 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2811.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2811.java @@ -13,7 +13,7 @@ class Problem2811 extends LeetcodeProblem { private int[] s; private int m; - public boolean canSplitArray(List _nums, int _m) { + boolean canSplitArray(List _nums, int _m) { int n = _nums.size(); f = new Boolean[n][n]; s = new int[n + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2818.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2818.java index 909e6dc9..a5b5d7d2 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2818.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2818.java @@ -11,7 +11,7 @@ class Problem2818 extends LeetcodeProblem { private final int mod = (int) 1e9 + 7; - public int maximumScore(List nums, int k) { + int maximumScore(List nums, int k) { int n = nums.size(); int[][] arr = new int[n][0]; for (int i = 0; i < n; i++) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2819.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2819.java index 5a9fa0be..e8087a6e 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2819.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2819.java @@ -12,7 +12,7 @@ class Problem2819 extends LeetcodeProblem { private int[] prices; private int len; - public long[] minimumRelativeLosses(int[] _prices, int[][] _queries) { + long[] minimumRelativeLosses(int[] _prices, int[][] _queries) { prices = _prices; len = _prices.length; Arrays.sort(_prices); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2827.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2827.java index 0ab0b36a..8a911430 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2827.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2827.java @@ -11,7 +11,7 @@ class Problem2827 extends LeetcodeProblem { private int k; private Integer[][][] f = new Integer[11][21][21]; - public int numberOfBeautifulIntegers(int _low, int _high, int _k) { + int numberOfBeautifulIntegers(int _low, int _high, int _k) { k = _k; s = String.valueOf(_high); int a = dfs(0, 0, 10, true, true); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2842.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2842.java index 9ee6b853..337f8d4c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2842.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2842.java @@ -11,7 +11,7 @@ class Problem2842 extends LeetcodeProblem { private final int mod = (int) 1e9 + 7; - public int countKSubsequencesWithMaxBeauty(String s, int k) { + int countKSubsequencesWithMaxBeauty(String s, int k) { int[] f = new int[26]; int n = s.length(); int cnt = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2844.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2844.java index bac3ac6e..54c72ab5 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2844.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2844.java @@ -11,7 +11,7 @@ class Problem2844 extends LeetcodeProblem { private int len; private Integer[][] f; - public int minimumOperations(String _num) { + int minimumOperations(String _num) { num = _num; len = _num.length(); f = new Integer[len][25]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2851.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2851.java index ed103417..fb627715 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2851.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2851.java @@ -76,7 +76,7 @@ private int[][] matrixPower(int[][] _a, long _y) { return r; } - public int numberOfWays(String _s, String _t, long _k) { + int numberOfWays(String _s, String _t, long _k) { int n = _s.length(); int[] dp = matrixPower(new int[][] {{0, 1}, {n - 1, n - 2}}, _k)[0]; _s += _t + _t; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2852.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2852.java index 344a27c3..33e3680c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2852.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2852.java @@ -11,7 +11,7 @@ class Problem2852 extends LeetcodeProblem { private int[][] grid; private int len; - public long sumRemoteness(int[][] _grid) { + long sumRemoteness(int[][] _grid) { grid = _grid; len = _grid.length; int cnt = 0; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2858.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2858.java index 94d31c56..96de1c12 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2858.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2858.java @@ -14,7 +14,7 @@ class Problem2858 extends LeetcodeProblem { private List[] g; private int[] ans; - public int[] minEdgeReversals(int _n, int[][] _edges) { + int[] minEdgeReversals(int _n, int[][] _edges) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2872.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2872.java index 2c79af90..bb81a02b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2872.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2872.java @@ -16,7 +16,7 @@ class Problem2872 extends LeetcodeProblem { private int[] values; private int k; - public int maxKDivisibleComponents(int _n, int[][] _edges, int[] _values, int _k) { + int maxKDivisibleComponents(int _n, int[][] _edges, int[] _values, int _k) { @SuppressWarnings("unchecked") List[] lists = new List[_n]; g = lists; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2896.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2896.java index 723686a3..3b9be6ea 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2896.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2800/Problem2896.java @@ -14,7 +14,7 @@ class Problem2896 extends LeetcodeProblem { private Integer[][] f; private int x; - public int minOperations(String _s1, String _s2, int _x) { + int minOperations(String _s1, String _s2, int _x) { int n = _s1.length(); for (int i = 0; i < n; i++) { if (_s1.charAt(i) != _s2.charAt(i)) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2902.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2902.java index 46da9e33..cc47f09a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2902.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2902.java @@ -13,7 +13,7 @@ class Problem2902 extends LeetcodeProblem { static final int MOD = 1_000_000_007; - public int countSubMultisets(List nums, int l, int r) { + int countSubMultisets(List nums, int l, int r) { Map count = new HashMap<>(); int total = 0; for (int num : nums) { diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2920.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2920.java index a0ccabec..bfb1531a 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2920.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2920.java @@ -16,7 +16,7 @@ class Problem2920 extends LeetcodeProblem { private Integer[][] f; private List[] g; - public int maximumPoints(int[][] _edges, int[] _coins, int _k) { + int maximumPoints(int[][] _edges, int[] _coins, int _k) { coins = _coins; k = _k; int n = _coins.length; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2925.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2925.java index 63dc638d..d4570f90 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2925.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2925.java @@ -14,7 +14,7 @@ class Problem2925 extends LeetcodeProblem { private List[] g; private int[] values; - public long maximumScoreAfterOperations(int[][] _edges, int[] _values) { + long maximumScoreAfterOperations(int[][] _edges, int[] _values) { int n = _values.length; @SuppressWarnings("unchecked") List[] lists = new List[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2930.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2930.java index f82e78f0..a6c75e42 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2930.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2930.java @@ -9,7 +9,7 @@ class Problem2930 extends LeetcodeProblem { private final int mod = (int) 1e9 + 7; - public int stringCount(int n) { + int stringCount(int n) { long a = qpow(25, n); long b = a; long c = (qpow(25, n) + n * qpow(25, n - 1) % mod) % mod; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2934.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2934.java index a3269efe..a806e546 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2934.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2934.java @@ -9,7 +9,7 @@ class Problem2934 extends LeetcodeProblem { private int n; - public int minOperations(int[] nums1, int[] nums2) { + int minOperations(int[] nums1, int[] nums2) { n = nums1.length; int a = f(nums1, nums2, nums1[n - 1], nums2[n - 1]); int b = f(nums1, nums2, nums2[n - 1], nums1[n - 1]); diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2944.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2944.java index 141b6433..1586b452 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2944.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2944.java @@ -11,7 +11,7 @@ class Problem2944 extends LeetcodeProblem { private int len; private int[] f; - public int minimumCoins(int[] _prices) { + int minimumCoins(int[] _prices) { prices = _prices; len = _prices.length; f = new int[len + 1]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2954.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2954.java index 4da8cb76..07967f2c 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2954.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2954.java @@ -18,7 +18,7 @@ class Problem2954 extends LeetcodeProblem { } } - public int numberOfSequence(int n, int[] sick) { + int numberOfSequence(int n, int[] sick) { int m = sick.length; int[] nums = new int[m + 1]; nums[0] = sick[0]; diff --git a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2967.java b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2967.java index 629717dd..b5644f00 100644 --- a/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2967.java +++ b/src/main/java/io/github/spannm/leetcode/lc2/lc2900/Problem2967.java @@ -24,7 +24,7 @@ class Problem2967 extends LeetcodeProblem { Arrays.sort(PS); } - public long minimumCost(int[] _nums) { + long minimumCost(int[] _nums) { nums = _nums; Arrays.sort(_nums); int i = Arrays.binarySearch(PS, _nums[_nums.length / 2]); diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3003.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3003.java index 55045f13..6eae2f29 100644 --- a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3003.java +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3003.java @@ -15,7 +15,7 @@ class Problem3003 extends LeetcodeProblem { private String s; private int k; - public int maxPartitionsAfterOperations(String _s, int _k) { + int maxPartitionsAfterOperations(String _s, int _k) { s = _s; k = _k; return dfs(0, 0, 1); diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3004.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3004.java index 28ac4c8b..348ec5fe 100644 --- a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3004.java +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3004.java @@ -17,7 +17,7 @@ class Problem3004 extends LeetcodeProblem { private int ans; @SuppressWarnings("unchecked") - public int maximumSubtreeSize(int[][] _edges, int[] _colors) { + int maximumSubtreeSize(int[][] _edges, int[] _colors) { int n = _edges.length + 1; g = new List[n]; size = new int[n]; diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3007.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3007.java index a75e6da4..bd5a217b 100644 --- a/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3007.java +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3000/Problem3007.java @@ -11,7 +11,7 @@ class Problem3007 extends LeetcodeProblem { private long num; private Long[][] f; - public long findMaximumNumber(long _k, int _x) { + long findMaximumNumber(long _k, int _x) { x = _x; long l = 1; long r = (long) 1e17; diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200.java new file mode 100644 index 00000000..498d876f --- /dev/null +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200.java @@ -0,0 +1,22 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeProblem; + +/** + * 3200. Maximum Height of a Triangle. + */ +class Problem3200 extends LeetcodeProblem { + + int maxHeightOfTriangle(int _red, int _blue) { + int result = 0; + for (int k = 0; k < 2; k++) { + int[] c = {_red, _blue}; + for (int i = 1, j = k; i <= c[j]; j ^= 1, i++) { + c[j] -= i; + result = Math.max(result, i); + } + } + return result; + } + +} diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201.java new file mode 100644 index 00000000..45e9fdd6 --- /dev/null +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201.java @@ -0,0 +1,24 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeProblem; + +/** + * 3201. Find the Maximum Length of Valid Subsequence I. + */ +class Problem3201 extends LeetcodeProblem { + + int maximumLength(int[] _nums) { + int[][] mem = new int[2][2]; + int result = 0; + for (int n : _nums) { + n %= 2; + for (int i = 0; i < 2; i++) { + int y = (i - n + 2) % 2; + mem[n][y] = mem[y][n] + 1; + result = Math.max(result, mem[n][y]); + } + } + return result; + } + +} diff --git a/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202.java b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202.java new file mode 100644 index 00000000..760a849b --- /dev/null +++ b/src/main/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202.java @@ -0,0 +1,24 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeProblem; + +/** + * 3202. Find the Maximum Length of Valid Subsequence II. + */ +class Problem3202 extends LeetcodeProblem { + + int maximumLength(int[] _nums, int _k) { + int[][] mem = new int[_k][_k]; + int result = 0; + for (int n : _nums) { + n %= _k; + for (int j = 0; j < _k; j++) { + int y = (j - n + _k) % _k; + mem[n][y] = mem[y][n] + 1; + result = Math.max(result, mem[n][y]); + } + } + return result; + } + +} diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011Test.java index 7e9eca1f..5db79484 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0011Test.java @@ -16,7 +16,7 @@ class Problem0011Test extends LeetcodeBaseTest { void test( @ConvertWith(CsvToIntArray.class) int[] _input, int _expectedResult) { - assertEquals(_expectedResult, new Problem0011().maxAreaOptimized(_input)); + assertEquals(_expectedResult, new Problem0011().maxArea(_input)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020Test.java index b86e7652..f0344393 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0020Test.java @@ -15,7 +15,7 @@ class Problem0020Test extends LeetcodeBaseTest { "((; false" }) void test(String _input, boolean _expectedResult) { - assertEquals(_expectedResult, new Problem0020().isValid2(_input)); + assertEquals(_expectedResult, new Problem0020().isValid(_input)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024Test.java index 10594d1e..20335011 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0024Test.java @@ -17,7 +17,7 @@ class Problem0024Test extends LeetcodeBaseTest { void test( @ConvertWith(CsvToListNode.class) ListNode _head, @ConvertWith(CsvToListNode.class) ListNode _expectedResult) { - assertEquals(_expectedResult, Problem0024.swapPairs(_head)); + assertEquals(_expectedResult, new Problem0024().swapPairs(_head)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086Test.java index 9f791442..08c28172 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0000/Problem0086Test.java @@ -18,7 +18,7 @@ void test( int _x, @ConvertWith(CsvToListNode.class) ListNode _expectedResult) { - ListNode result = Problem0086.partition(_head, _x); + ListNode result = new Problem0086().partition(_head, _x); assertEquals(_expectedResult, result); } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169Test.java index 7b3b60e9..1e0c91a5 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0100/Problem0169Test.java @@ -16,7 +16,7 @@ class Problem0169Test extends LeetcodeBaseTest { void test( @ConvertWith(CsvToIntArray.class) int[] _nums, int _expectedResult) { - assertEquals(_expectedResult, new Problem0169().majorityElement2(_nums)); + assertEquals(_expectedResult, new Problem0169().majorityElement(_nums)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420Test.java index 95158125..cdaa051c 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0400/Problem0420Test.java @@ -17,7 +17,7 @@ class Problem0420Test extends LeetcodeBaseTest { "bbaaaaaaaaaaaaaaaccc; 6" }) void test(String _password, int _expectedResult) { - assertEquals(_expectedResult, new Problem0420().strongPasswordChecker3(_password)); + assertEquals(_expectedResult, new Problem0420().strongPasswordChecker(_password)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946Test.java b/src/test/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946Test.java index 7c86c16f..96fa7ef5 100644 --- a/src/test/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc0/lc0900/Problem0946Test.java @@ -16,7 +16,7 @@ void test( @ConvertWith(CsvToIntArray.class) int[] _pushed, @ConvertWith(CsvToIntArray.class) int[] _popped, boolean _expectedResult) { - assertEquals(_expectedResult, new Problem0946().validateStackSequences2(_pushed, _popped)); + assertEquals(_expectedResult, new Problem0946().validateStackSequences(_pushed, _popped)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011Test.java b/src/test/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011Test.java index b1a85f11..099b8752 100644 --- a/src/test/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc1/lc1000/Problem1011Test.java @@ -20,7 +20,7 @@ void test( int _days, int _expectedCapacity) { - assertEquals(_expectedCapacity, new Problem1011().shipWithinDays2(_weights, _days)); + assertEquals(_expectedCapacity, new Problem1011().shipWithinDays(_weights, _days)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464Test.java b/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464Test.java index 899e6527..9330824c 100644 --- a/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1464Test.java @@ -16,7 +16,7 @@ class Problem1464Test extends LeetcodeBaseTest { void test( @ConvertWith(CsvToIntArray.class) int[] _nums, int _expectedResult) { - assertEquals(_expectedResult, new Problem1464().maxProduct2(_nums)); + assertEquals(_expectedResult, new Problem1464().maxProduct(_nums)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491Test.java b/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491Test.java index 8d200927..001c388e 100644 --- a/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc1/lc1400/Problem1491Test.java @@ -16,7 +16,7 @@ void test( @ConvertWith(CsvToIntArray.class) int[] _salary, double _expectedResult) { - assertEquals(_expectedResult, Problem1491.average(_salary)); + assertEquals(_expectedResult, new Problem1491().average(_salary)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090Test.java b/src/test/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090Test.java index 6654f596..b2e59391 100644 --- a/src/test/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090Test.java +++ b/src/test/java/io/github/spannm/leetcode/lc2/lc2000/Problem2090Test.java @@ -5,8 +5,6 @@ import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; -import java.util.Arrays; - class Problem2090Test extends LeetcodeBaseTest { @ParameterizedTest(name = "[{index}] [{0}], {1} --> [{2}]") @@ -20,10 +18,7 @@ void test( int _k, @ConvertWith(CsvToIntArray.class) int[] _expectedResult) { - int[] result = new Problem2090().getAverages(_nums, _k); - assertEquals(Arrays.toString(_expectedResult), Arrays.toString(result)); - assertArrayEquals(_expectedResult, result); - + assertArrayEquals(_expectedResult, new Problem2090().getAverages(_nums, _k)); } } diff --git a/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200Test.java b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200Test.java new file mode 100644 index 00000000..1e37835b --- /dev/null +++ b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3200Test.java @@ -0,0 +1,18 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeBaseTest; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class Problem3200Test extends LeetcodeBaseTest { + @ParameterizedTest(name = "[{index}] {0}; {1} --> {2}") + @CsvSource(delimiter = ';', value = { + "2; 4; 3", + "2; 1; 2", + "1; 1; 1", + "10; 1; 2" + }) + void test(int _red, int _blue, int _expectedResult) { + assertEquals(_expectedResult, new Problem3200().maxHeightOfTriangle(_red, _blue)); + } +} diff --git a/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201Test.java b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201Test.java new file mode 100644 index 00000000..c2950ad8 --- /dev/null +++ b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3201Test.java @@ -0,0 +1,18 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeBaseTest; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.provider.CsvSource; + +class Problem3201Test extends LeetcodeBaseTest { + @ParameterizedTest(name = "[{index}] {0} --> {1}") + @CsvSource(delimiter = ';', value = { + "1,2,3,4; 4", + "1,2,1,1,2,1,2; 6", + "1,3; 2" + }) + void test(@ConvertWith(CsvToIntArray.class) int[] _nums, int _expectedResult) { + assertEquals(_expectedResult, new Problem3201().maximumLength(_nums)); + } +} diff --git a/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202Test.java b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202Test.java new file mode 100644 index 00000000..04c60f24 --- /dev/null +++ b/src/test/java/io/github/spannm/leetcode/lc3/lc3200/Problem3202Test.java @@ -0,0 +1,17 @@ +package io.github.spannm.leetcode.lc3.lc3200; + +import io.github.spannm.leetcode.LeetcodeBaseTest; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.provider.CsvSource; + +class Problem3202Test extends LeetcodeBaseTest { + @ParameterizedTest(name = "[{index}] {0}; {1} --> {2}") + @CsvSource(delimiter = ';', value = { + "1,2,3,4,5; 2; 5", + "1,4,2,3,1,4; 3; 4" + }) + void test(@ConvertWith(CsvToIntArray.class) int[] _nums, int _k, int _expectedResult) { + assertEquals(_expectedResult, new Problem3202().maximumLength(_nums, _k)); + } +}