From cf6c2cb2c35a2f4704fb751769f10eac56e3ddd7 Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 17:06:08 +0800 Subject: [PATCH 1/6] =?UTF-8?q?1814.=20=E7=BB=9F=E8=AE=A1=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=95=B0=E7=BB=84=E4=B8=AD=E5=A5=BD=E5=AF=B9=E5=AD=90?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeetCode/META-INF/LeetCode.kotlin_module | Bin 24 -> 241 bytes src/solutions/leetcode/normal/Solution1814.kt | 37 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/solutions/leetcode/normal/Solution1814.kt diff --git a/out/production/LeetCode/META-INF/LeetCode.kotlin_module b/out/production/LeetCode/META-INF/LeetCode.kotlin_module index 8c840ddb016f7cb30515434c461f671bc32f92d9..ab6f1c072518fa36a326b6955ca995daba2f8f17 100644 GIT binary patch literal 241 zcmZQzU|?ooU|4w70^?-C@Q8IZ>ZH^;&NjSn(eh!-JmiK5v8g@+<%1kwn1pb1814. 统计一个数组中好对子的数目 + */ +class Solution1814 { + fun countNicePairs(nums: IntArray): Int { + val map = HashMap() + var count = 0 + val mod = 1000000007 + for (item in nums) { + val offset = item - rev(item) + val c = map.getOrDefault(offset, 0) + count = (count + c).mod(mod) + map[offset] = (c + 1).mod(mod) + } + return count + } + + private fun rev(value: Int): Int { + var num = value + var rst = 0 + while (num > 0) { + rst *= 10 + rst += num % 10 + num /= 10 + } + return rst + } +} + +fun main() { + println(Solution1814().countNicePairs(arrayOf( + 13,10,35,24,76 + ).toIntArray())) +} \ No newline at end of file -- Gitee From f34b80afb310add727fb612a7680936d389caf4d Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 17:16:20 +0800 Subject: [PATCH 2/6] =?UTF-8?q?1798.=20=E4=BD=A0=E8=83=BD=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BA=E8=BF=9E=E7=BB=AD=E5=80=BC=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/solutions/leetcode/normal/Solution1798.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/solutions/leetcode/normal/Solution1798.kt diff --git a/src/solutions/leetcode/normal/Solution1798.kt b/src/solutions/leetcode/normal/Solution1798.kt new file mode 100644 index 0000000..b53536c --- /dev/null +++ b/src/solutions/leetcode/normal/Solution1798.kt @@ -0,0 +1,24 @@ +package solutions.leetcode.normal + +/** + * @author lizhidong + * 1798. 你能构造出连续值的最大数目 + */ +private class Solution1798 { + fun getMaximumConsecutive(coins: IntArray): Int { + coins.sort() + var max = 1 + for (item in coins) { + if (item > max) { + break + } else { + max += item + } + } + return max + } +} + +fun main() { + +} \ No newline at end of file -- Gitee From 9d9909f067752d72e9f7ecb4af40c1a2ce557341 Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 17:35:36 +0800 Subject: [PATCH 3/6] =?UTF-8?q?1807.=20=E6=9B=BF=E6=8D=A2=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E4=B8=AD=E7=9A=84=E6=8B=AC=E5=8F=B7=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeetCode/META-INF/LeetCode.kotlin_module | Bin 241 -> 273 bytes src/solutions/leetcode/normal/Solution1807.kt | 41 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/solutions/leetcode/normal/Solution1807.kt diff --git a/out/production/LeetCode/META-INF/LeetCode.kotlin_module b/out/production/LeetCode/META-INF/LeetCode.kotlin_module index ab6f1c072518fa36a326b6955ca995daba2f8f17..c5e60494c1f2443efdde75b6e51556bc12c2593b 100644 GIT binary patch delta 50 scmey!IFV_B9pl-F_Rh-YmKNS6LVUsbIi)3;`FVyG24-k{^NFoF0Ht9NnE(I) delta 18 acmbQp^pSCb9pl=G_Rh=}24)kN<^TXZl?GS< diff --git a/src/solutions/leetcode/normal/Solution1807.kt b/src/solutions/leetcode/normal/Solution1807.kt new file mode 100644 index 0000000..4562781 --- /dev/null +++ b/src/solutions/leetcode/normal/Solution1807.kt @@ -0,0 +1,41 @@ +package solutions.leetcode.normal + +/** + * @author lizhidong + * 1807. 替换字符串中的括号内容 + */ +private class Solution1807 { + fun evaluate(s: String, knowledge: List>): String { + val sb = StringBuilder() + val map = knowledge.associate { it[0] to it[1] } + var ind = 0 + while (ind < s.length) { + val c = s[ind++] + if (c == '(') { + val key = StringBuilder() + while (ind < s.length) { + val cc = s[ind++] + if (cc == ')') { + break + } + key.append(cc) + } + sb.append(map[key.toString()] ?: "?") + } else { + sb.append(c) + } + } + return sb.toString() + } +} + +fun main() { + println(Solution1807().evaluate( + "(name)is(age)yearsold", + arrayListOf( + arrayListOf( + "name","bob" + ) + ) + )) +} \ No newline at end of file -- Gitee From d54cfca214ac27de99fcb70dbf1fe06c9310ee00 Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 17:55:43 +0800 Subject: [PATCH 4/6] =?UTF-8?q?1829.=20=E6=AF=8F=E4=B8=AA=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=9A=84=E6=9C=80=E5=A4=A7=E5=BC=82=E6=88=96=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeetCode/META-INF/LeetCode.kotlin_module | Bin 273 -> 289 bytes src/solutions/leetcode/normal/Solution1829.kt | 25 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/solutions/leetcode/normal/Solution1829.kt diff --git a/out/production/LeetCode/META-INF/LeetCode.kotlin_module b/out/production/LeetCode/META-INF/LeetCode.kotlin_module index c5e60494c1f2443efdde75b6e51556bc12c2593b..cd3783d9e2d2378eade43859e3b11a0db49b8775 100644 GIT binary patch delta 28 kcmbQpw2*0n9pl}J_LaPR!TC9*C7Jnoh89Ma6Su|y0FIRk8UO$Q delta 14 WcmZ3;G?8h79pl-F_LUP)L;?UOY6Z>! diff --git a/src/solutions/leetcode/normal/Solution1829.kt b/src/solutions/leetcode/normal/Solution1829.kt new file mode 100644 index 0000000..6e463fa --- /dev/null +++ b/src/solutions/leetcode/normal/Solution1829.kt @@ -0,0 +1,25 @@ +package solutions.leetcode.normal + +/** + * @author lizhidong + * 1829. 每个查询的最大异或值 + */ +private class Solution1829 { + fun getMaximumXor(nums: IntArray, maximumBit: Int): IntArray { + val rst = IntArray(nums.size) + val sum = Math.pow(2.0, maximumBit.toDouble()).toInt() + var now = 0 + for ((ind, item) in nums.withIndex()) { + now = now xor item + rst[nums.size - 1 - ind] = sum - 1 - now % sum + } + return rst + } +} + +fun main() { + println(Solution1829().getMaximumXor( + arrayOf(0,1,2,2,5,7).toIntArray(), + 3 + ).toList()) +} \ No newline at end of file -- Gitee From b1ac499d539b06903f3696e76dff83f547c34543 Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 18:15:05 +0800 Subject: [PATCH 5/6] =?UTF-8?q?1817.=20=E6=9F=A5=E6=89=BE=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B4=BB=E8=B7=83=E5=88=86=E9=92=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/solutions/leetcode/normal/Solution1817.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/solutions/leetcode/normal/Solution1817.kt diff --git a/src/solutions/leetcode/normal/Solution1817.kt b/src/solutions/leetcode/normal/Solution1817.kt new file mode 100644 index 0000000..c73d830 --- /dev/null +++ b/src/solutions/leetcode/normal/Solution1817.kt @@ -0,0 +1,39 @@ +package solutions.leetcode.normal + +/** + * @author lizhidong + * 1817. 查找用户活跃分钟数 + */ +private class Solution1817 { + fun findingUsersActiveMinutes(logs: Array, k: Int): IntArray { + val map = HashMap>() + for (item in logs) { + var set = map[item[0]] + if (set == null) { + set = HashSet() + map[item[0]] = set + } + if (item[1] <= k) set.add(item[1]) + } + val rst = IntArray(k) + map.map { it.value.size }.filter { it > 0 }.forEach { + rst[it - 1]++ + } + return rst + } +} + +fun main() { + println( + Solution1817().findingUsersActiveMinutes( + arrayOf( + arrayOf(0, 5).toIntArray(), + arrayOf(1, 2).toIntArray(), + arrayOf(0, 2).toIntArray(), + arrayOf(0, 2).toIntArray(), + arrayOf(1, 3).toIntArray(), + ), + 5 + ).toList() + ) +} \ No newline at end of file -- Gitee From 7d88a80bfe3755395e1b383e8c79caa01343d0ba Mon Sep 17 00:00:00 2001 From: lizhidong Date: Tue, 17 Jan 2023 18:19:21 +0800 Subject: [PATCH 6/6] remove unused --- .gitignore | 1 + .../LeetCode/META-INF/LeetCode.kotlin_module | Bin 289 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 out/production/LeetCode/META-INF/LeetCode.kotlin_module diff --git a/.gitignore b/.gitignore index 13087c6..b966fe4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # BlueJ files *.ctxt +out/ # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/out/production/LeetCode/META-INF/LeetCode.kotlin_module b/out/production/LeetCode/META-INF/LeetCode.kotlin_module deleted file mode 100644 index cd3783d9e2d2378eade43859e3b11a0db49b8775..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 289 zcmZQzU|?ooU|4w70^?-C@Q8IZ>ZH^ni)6J$7ohazVLG6*h*YK*Z3P*RCOiva-5$5?y- -- Gitee