
LeetCode
Alicization~Iris
做一个低调的人……
展开
-
56. 合并区间 LeetCode(详细讲解 & 图示 & 注释)
原题地址:56. 合并区间 LeetCode题目大意:给出若干个区间,合并重叠的区间,返回一个合并后的区间的集合。思路解析:class Solution {public: vector<vector<int>> merge(vector<vector<int>>& intervals) { // 区间的个数 int len = intervals.size(); // 根据左边界大小快排原创 2021-09-29 17:30:38 · 1178 阅读 · 0 评论 -
剑指 Offer 10- I. 斐波那契数列
原题地址:剑指 Offer 10- I. 斐波那契数列题目中有说最终结果可能比较大,需要对1000000007取模,因此求fib(n)的过程中很可能就会超出int的范围,所以我们需要先根据取模运算的一个原理对中间的数据进行处理,然后再求对应的结果。class Solution { public int fib(int n) { if (n == 0) { return 0; } if (n == 1) {原创 2021-09-23 11:17:20 · 186 阅读 · 0 评论 -
剑指 Offer 32 从上到下打印二叉树 (系列题目,包含Ⅰ~Ⅲ)
系列题目1:剑指 Offer 32 - I. 从上到下打印二叉树思路:实现一个二叉树的层序遍历,使用队列实现/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { publ原创 2021-09-21 12:02:40 · 156 阅读 · 0 评论 -
NC111 最大数 牛客网(详细注释及图解)
牛客网原题地址:NC111 最大数import java.util.*;public class Solution { /** * 最大数 * @param nums int整型一维数组 * @return string字符串 */ public String solve (int[] nums) { // write code here // 求数组中所有数的和,用于判断特殊情况,即数组中全是0的情况原创 2021-09-18 15:07:01 · 364 阅读 · 0 评论 -
剑指 Offer 35. 复杂链表的复制 LeetCode
LeetCode原题地址:剑指 Offer 35. 复杂链表的复制思路:先复制next,再复制random/*// Definition for a Node.class Node { int val; Node next; Node random; public Node(int val) { this.val = val; this.next = null; this.random = null; }}原创 2021-09-17 13:22:19 · 93 阅读 · 0 评论 -
1668. 最大重复子字符串 LeetCode-字符串匹配
LeetCode原题:1668. 最大重复子字符串class Solution { public int maxRepeating(String sequence, String word) { // 模式串长度大于原字符串,返回0 if (word.length() > sequence.length()) { return 0; } // 原字符串中一个模式串都没有,返回0 if (sequ原创 2021-09-17 08:35:57 · 462 阅读 · 0 评论 -
459. 重复的子字符串 LeetCode-字符串匹配
LeetCode题目:459. 重复的子字符串class Solution { public boolean repeatedSubstringPattern(String s) { int length = s.length(); // 至少是由两个相同的子字符串构成,所以子字符串的长度最大为s的一半 for (int i = 1; i <= length / 2; i++) { // 初始字符串长度是子字符串长度的倍数时才原创 2021-09-16 17:03:48 · 131 阅读 · 0 评论 -
204. 计数质数 LeetCode-枚举
204. 计数质数厄拉多塞筛法求小于n的质数的个数class Solution { public int countPrimes(int n) { // 厄拉多塞筛法 boolean[] isPrime = new boolean[n]; int count = 0; for (int i = 2; i < n; i++) { if (!isPrime[i]) { cou原创 2021-09-16 15:23:28 · 129 阅读 · 0 评论 -
463. 岛屿的周长 LeetCode-矩阵
矩阵相关题目:463. 岛屿的周长class Solution { // 题目中有说只会出现一个岛屿,所以我们只需要求出这个岛屿的周长即可 public int islandPerimeter(int[][] grid) { int row = grid.length; int col = grid[0].length; int per = 0; for (int i = 0; i < row; i++) {原创 2021-09-15 21:17:56 · 115 阅读 · 0 评论 -
67. 二进制求和 LeetCode-字符串
LeetCode题目:67. 二进制求和字符串相关题目,使用栈来实现class Solution { public String addBinary(String a, String b) { Stack<Integer> num1 = new Stack<>(); Stack<Integer> num2 = new Stack<>(); Stack<Integer> sum = new原创 2021-09-15 20:08:28 · 112 阅读 · 0 评论