摘要: Valid Anagram Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearrangin 阅读全文
posted @ 2022-10-23 12:49 iyiluo 阅读(23) 评论(0) 推荐(0)
摘要: Remove Linked List Elements Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and 阅读全文
posted @ 2022-10-23 12:15 iyiluo 阅读(27) 评论(0) 推荐(0)
摘要: Move Zeroes 思路一: 用 left 指针标记求解数组最大下标 + 1,初始化的时候是 0,随着往右遍历,left 会一步步扩大。最后把 left 右边的数都置为 0。 这题的关键在于 left 永远指向求解数组最大下标 + 1 public void moveZeroes(int[] n 阅读全文
posted @ 2022-10-23 09:08 iyiluo 阅读(13) 评论(0) 推荐(0)
摘要: Power Of Two 思路一: 观察 2 的 n 次方的二进制,都只有一位 1 bit,遍历即可 public boolean isPowerOfTwo(int n) { if (n <= 0) return false; int count = 0; for (int i = 0; i < 3 阅读全文
posted @ 2022-10-23 08:35 iyiluo 阅读(12) 评论(0) 推荐(0)
摘要: Majority Element 思路一: map public int majorityElement(int[] nums) { if (nums.length == 1) return nums[0]; Map<Integer, Integer> map = new HashMap<>(); 阅读全文
posted @ 2022-10-22 22:20 iyiluo 阅读(16) 评论(0) 推荐(0)
摘要: Reverse Bits 思路一: 遍历 32 位 bit,记录 bit 结果 public int reverseBits(int n) { int result = 0; int x = 32; while (x-- > 0) { int bit = n & 1; result <<= 1; i 阅读全文
posted @ 2022-10-22 20:54 iyiluo 阅读(17) 评论(0) 推荐(0)
摘要: 下面操作是在虚拟机环境下,根目录最好不要扩容或者缩小,一旦出问题很容易导致系统启动分区故障 查看磁盘信息fdisk -l Disk /dev/sda: 48 GiB, 51539607552 bytes, 100663296 sectors ... Device Boot Start End Sec 阅读全文
posted @ 2022-10-22 19:56 iyiluo 阅读(1227) 评论(0) 推荐(0)
摘要: Long Pressed Name 思路一: 暴力,遍历两个字符串,对比。边界情况不太好处理 public boolean isLongPressedName(String name, String typed) { if (typed.length() < name.length()) retur 阅读全文
posted @ 2022-10-19 21:19 iyiluo 阅读(15) 评论(0) 推荐(0)
摘要: X of a Kind in a Deck of Cards 思路一: 统计数字个数,然后用 [2, length] 的约数尝试所有数字个数,判断能否整除 public boolean hasGroupsSizeX(int[] deck) { Map<Integer, Integer> map = 阅读全文
posted @ 2022-10-19 21:18 iyiluo 阅读(15) 评论(0) 推荐(0)
摘要: Monotonic Array 思路一: 遍历 public boolean isMonotonic(int[] nums) { boolean increase = true; for (int i = 0; i < nums.length - 1; i++) { if (nums[i] > nu 阅读全文
posted @ 2022-10-19 21:17 iyiluo 阅读(14) 评论(0) 推荐(0)