Loading

上一页 1 ··· 5 6 7 8 9 10 11 下一页
摘要: 题目链接:剑指 Offer 56 - II. 数组中数字出现的次数 II 官方题解:面试题56 - II. 数组中数字出现的次数 II(位运算 + 有限状态自动机,清晰图解) 思路:数组中只有一个数字出现一次,其他数字出现三次,那么可以统计二进制各个位数上各自1出现的次数,然后模3,那么最后得到的二 阅读全文
posted @ 2020-12-07 14:09 yoyuLiu 阅读(52) 评论(0) 推荐(0) 编辑
摘要: 题目链接:861. 翻转矩阵后的得分 思路:给一个0-1矩阵,每行表示一个二进制数,要求翻转矩阵后的各行之和的值最高。那么只要保证矩阵每列中的1出现次数最多就行,对于第一列,应该通过翻转使它全部为1,然后对后面的矩阵列只要保证每列1出现的次数大于等于矩阵行数一半就行。 代码: class Solut 阅读全文
posted @ 2020-12-07 10:36 yoyuLiu 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/ 思路:滑动窗口。用map记录每个字符出现的位置。当字符不在map中时,就往map中添加字符和位置,当字符在map中时 阅读全文
posted @ 2020-12-06 12:42 yoyuLiu 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/task-scheduler/submissions/ 官方题解:任务调度器 代码: class Solution { public int leastInterval(char[] tasks, int n) { char[] 阅读全文
posted @ 2020-12-05 15:24 yoyuLiu 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/split-array-into-consecutive-subsequences/ 题意:将一个排序好的数组分割成多个长度不小于3的连续子序列,例如:输入[1,2,2,3,3,4],有“1,2,3”、“2,3,4”,可以分割; 阅读全文
posted @ 2020-12-04 13:50 yoyuLiu 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/ 代码: class Solution { public int movingCount(int m, int n, int k) { LinkedList< 阅读全文
posted @ 2020-12-04 02:03 yoyuLiu 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/ 思路:从左往右遍历一遍,再从左往右遍历。 代码: class Solution { public int[] constructArr(int[] a) { int[ 阅读全文
posted @ 2020-12-03 13:37 yoyuLiu 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/ 代码: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo 阅读全文
posted @ 2020-12-03 00:12 yoyuLiu 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/reorganize-string/submissions/ 题解:要使相邻的字符不重复,那么存在一种情况:当一个字符出现次数大于总字符数一半时,那么一定存在相同字符相邻。为了不使相同字符相邻,那么每个字符都应该与自己上一个字符 阅读全文
posted @ 2020-11-30 18:02 yoyuLiu 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 题目:https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/submissions/ 代码: class Solution { public boolean exist(char[][] board, String word) 阅读全文
posted @ 2020-11-29 14:57 yoyuLiu 阅读(50) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 下一页