随笔分类 -  Java

上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
使用java编写的程序或者和java有关的题目
摘要:189. 旋转数组 LeetCode_189 题目描述 方法一:使用暴力法 class Solution { public void rotate(int[] nums, int k) { int n = nums.length; int[] second = new int[n]; for(int 阅读全文
posted @ 2021-03-10 19:55 Garrett_Wale 阅读(58) 评论(0) 推荐(0) 编辑
摘要:什么是零拷贝 WIKI中对其有如下定义: "Zero-copy" describes computer operations in which the CPU does not perform the task of copying data from one memory area to anot 阅读全文
posted @ 2021-03-10 10:03 Garrett_Wale 阅读(810) 评论(0) 推荐(0) 编辑
摘要:300. 最长递增子序列 题目描述 方法一:动态规划 与53. 最大子数组和 + 动态规划 + 线段树 问题类似,本题属于子序列问题的一种。 问题的关键是定义好dp动态方程,类似于LeetCode-53题目,我们假设dp[i]表示i结尾的递增子序列的长度。 对于状态转移方程,我们可以这样考虑:因为是 阅读全文
posted @ 2021-03-09 22:23 Garrett_Wale 阅读(123) 评论(0) 推荐(0) 编辑
摘要:958. 二叉树的完全性检验 LeetCode_958 题目描述 题解分析 题目的关键是判断每一层的结点数是否等于2^i。 此外,还有一个比较关键的因素是判断最后一层的结点是否是偏左的。 以上这两点都可以通过给每个结点设置一个序号,也就是按照二叉树的顺序存储的方式分配序号,如果最后一个结点的序号和所 阅读全文
posted @ 2021-03-09 20:13 Garrett_Wale 阅读(75) 评论(0) 推荐(0) 编辑
摘要:题目来源 LeetCode_42 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 题目详情 示例 1: 输入: height = [0,1,0,2,1,0,1,3,2,1,2,1] 输出: 6 解释: 上面是由数组 [0,1,0,2,1,0,1,3 阅读全文
posted @ 2021-03-08 21:12 Garrett_Wale 阅读(216) 评论(0) 推荐(0) 编辑
摘要:题目来源 LeetCode_53 题目描述 给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 子数组 是数组中的一个连续部分。 示例 1: 输入: nums = [-2,1,-3,4,-1,2,1,-5,4] 输出: 6 解释: 连续子数组  阅读全文
posted @ 2021-03-08 20:24 Garrett_Wale 阅读(109) 评论(0) 推荐(0) 编辑
摘要:103. 二叉树的锯齿形层序遍历 LeetCode_103 相似题型:剑指 Offer 32 - III. 从上到下打印二叉树 III 题目描述 LinkedList(Deque的一个实现类)的用法 增加: add(E e):在链表后添加一个元素; 通用方法 addFirst(E e):在链表头部插 阅读全文
posted @ 2021-03-08 19:57 Garrett_Wale 阅读(94) 评论(0) 推荐(0) 编辑
摘要:面试官: Java并发这块了解的怎么样?说说你对volatile关键字的理解 就我理解的而言,被volatile修饰的共享变量,就具有了以下两点特性: 1.保证了不同线程对该变量操作的内存可见性; 2.禁止指令重排序 面试官: 能不能详细说下什么是内存可见性,什么又是重排序呢? 这个聊起来可就多了, 阅读全文
posted @ 2021-03-07 21:45 Garrett_Wale 阅读(447) 评论(0) 推荐(0) 编辑
摘要:题目来源 LeetCode_46 题目描述 给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。 示例 1: 输入: nums = [1,2,3] 输出: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 阅读全文
posted @ 2021-03-07 21:24 Garrett_Wale 阅读(81) 评论(0) 推荐(0) 编辑
摘要:232. 用栈实现队列 LeetCode_232 题目描述 方法一:在push时将原有栈的元素全部出栈然后再将当前元如入栈,最后再将第二个栈的元素入第一个栈 class MyQueue{ int num; Deque<Integer> sta1, sta2;//使用双端队列来模拟栈 /** Init 阅读全文
posted @ 2021-03-07 20:54 Garrett_Wale 阅读(75) 评论(0) 推荐(0) 编辑
摘要:54. 螺旋矩阵 LeetCode_54 相似题目:剑指 Offer 29. 顺时针打印矩阵 题目描述 代码实现 class Solution { public List<Integer> spiralOrder(int[][] matrix) { int m = matrix.length;//行 阅读全文
posted @ 2021-03-07 20:23 Garrett_Wale 阅读(112) 评论(0) 推荐(0) 编辑
摘要:题目来源 LeetCode_69 题目详情 题解分析 方法一:使用sqrt class Solution { public int mySqrt(int x) { return (int)Math.sqrt((double)x); } } 方法二:袖珍计算器 class Solution { pub 阅读全文
posted @ 2021-03-07 20:04 Garrett_Wale 阅读(73) 评论(0) 推荐(0) 编辑
摘要:415. 字符串相加 LeetCode_415 题目详情 方法一:使用暴力法 class Solution { public String addStrings(String num1, String num2) { int len1 = num1.length(); int len2 = num2 阅读全文
posted @ 2021-03-06 21:44 Garrett_Wale 阅读(98) 评论(0) 推荐(0) 编辑
摘要:145. 二叉树的后序遍历 LeetCode_145 题目描述 递归解法 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; 阅读全文
posted @ 2021-03-05 18:57 Garrett_Wale 阅读(59) 评论(0) 推荐(0) 编辑
摘要:94. 二叉树的中序遍历 LeetCode_94 题目描述 解法一:递归解法 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right 阅读全文
posted @ 2021-03-05 18:40 Garrett_Wale 阅读(119) 评论(0) 推荐(0) 编辑
摘要:160. 相交链表 LeetCode_160 题目描述 题解分析 本题使用的方法是双指针法,题目和环形链表相似,都是利用链表的特性来求解。 当遍历链表a到达尾部时,再指向链表b的头部;当遍历链表b到末尾时,再指向链表a的头部。 再次相遇时便是相交结点。 java代码 /** * Definition 阅读全文
posted @ 2021-03-05 17:59 Garrett_Wale 阅读(64) 评论(0) 推荐(0) 编辑
摘要:142. 环形链表 II LeetCode_142 题目描述 题解分析 判断链表是否存在环 对于这个问题我们可以采用“快慢指针”的方法。就是有两个指针fast和slow,开始的时候两个指针都指向链表头head,然后在每一步操作中slow向前走一步即:slow = slow->next,而fast每一 阅读全文
posted @ 2021-03-04 21:57 Garrett_Wale 阅读(76) 评论(0) 推荐(0) 编辑
摘要:1.总述 java命令用来启动一个java应用。有以下两种用法: java [options] mainClass [args...] java [options] -jar jarfile [args...] 第一种从指定的java类开始启动,第二种从可运行的jar开始启动。java应用启动的过程 阅读全文
posted @ 2021-03-04 17:55 Garrett_Wale 阅读(952) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
点击右上角即可分享
微信分享提示