摘要: ###java内存简单分析 #####堆 1.存放new的对象和数组 2.可以被所有的线程共享,不会存放别的对象的引用 #####栈 1.存放基本变量类型(会包含这个基本类型的具体参数) 2.引用对象的变量(会存放这个引用在堆里面的具体地址) #####方法区(属于堆) 1.可以被所有的线程共享 2 阅读全文
posted @ 2020-09-26 23:41 SSunSShine 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 5. 172_阶乘后的零 /* 给定一个整数 n,返回 n! 结果尾数中零的数量。 */ /** * 算一下乘法因子里有多少个5 * 找因子直接遍历(o(n)超时) */ public class Solution { public int trailingZeroes(int num) { int 阅读全文
posted @ 2020-09-26 19:45 SSunSShine 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 4. 43_字符串相乘 /* 给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。 */ /* O(mn+n²),O(m+n) */ class Solution { public String multiply(Strin 阅读全文
posted @ 2020-09-26 19:44 SSunSShine 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 3. 9_ 回文数 /** * 不转换成String 反转一半的数字o(log(n)) */ public class Solution { public boolean isPalindrome(int x) { if (x < 0) { return false; } if (x < 10) { 阅读全文
posted @ 2020-09-26 19:43 SSunSShine 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 2. 8_字符串转换整数(atoi) /* 请你来实现一个 atoi 函数,使其能将字符串转换成整数。 */ class Solution { public int myAtoi(String str) { str = str.trim(); if(str == null || str.length 阅读全文
posted @ 2020-09-26 19:42 SSunSShine 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 1. 7_整数反转 /* 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。 输入: 123 -123 120 输出: 321 -321 21 如果反转后整数溢出那么就返回 0。 */ /** * 求余(判断是否溢出有多种方式) o(log(n)) */ class Solut 阅读全文
posted @ 2020-09-26 19:41 SSunSShine 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 3. 763_划分字母区间 /* 输入:S = "ababcbacadefegdehijhklij" 输出:[9,7,8] 解释: 划分结果为 "ababcbaca", "defegde", "hijhklij"。 每个字母最多出现在一个片段中。 像 "ababcbacadefegde", "hij 阅读全文
posted @ 2020-09-26 19:40 SSunSShine 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 2. 14_最长公共前缀 /* 输入: ["flower","flow","flight"] 输出: "fl" */ class Solution { public String longestCommonPrefix(String[] strs) { if(strs == null || strs 阅读全文
posted @ 2020-09-26 19:39 SSunSShine 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 1. 6_Z字形变换 /* 输入: s = "LEETCODEISHIRING", numRows = 4 输出: "LDREOEIIECIHNTSG" 解释: L D R E O E I I E C I H N T S G */ class Solution { public String con 阅读全文
posted @ 2020-09-26 19:38 SSunSShine 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 1. 56_合并区间 /* 输入: intervals = [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6]. */ class Solution { publi 阅读全文
posted @ 2020-09-26 19:37 SSunSShine 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 3. 876_链表的中间结点 /* 给定一个带有头结点 head 的非空单链表,返回链表的中间结点。 如果有两个中间结点,则返回第二个中间结点。 */ class Solution { public ListNode middleNode(ListNode head) { ListNode fast 阅读全文
posted @ 2020-09-26 19:36 SSunSShine 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 2. 202_快乐数 /* 编写一个算法来判断一个数 n 是不是快乐数。 「快乐数」定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。如果 可以变为 1,那么这个数就是快乐数。 如果 n 是快乐数就返回 T 阅读全文
posted @ 2020-09-26 19:35 SSunSShine 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 1. 141_环形链表 /* 给定一个链表,判断链表中是否有环。 */ /** * 哈希表 o(n) */ public class Solution { public boolean hasCycle(ListNode head) { Set<ListNode> nodesSeen = new H 阅读全文
posted @ 2020-09-26 19:34 SSunSShine 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 8. 209_长度最小的子数组 /* 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的 连续 子数组,并返回其长度。如果不存在符合条件的子数组,返回 0。 */ class Solution { public int minSubArrayLen(int 阅读全文
posted @ 2020-09-26 19:33 SSunSShine 阅读(44) 评论(0) 推荐(0) 编辑
摘要: 7. 121_买卖股票的最佳时机 /* 输入: [7,1,5,3,6,4] 输出: 5 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。 注意利润不能是 7-1 = 6, 因为卖出价格需要大于买入价格;同时,你不能在买入 阅读全文
posted @ 2020-09-26 19:31 SSunSShine 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 6. 42_接雨水 /* 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水) */ /* 暴力解, O(n²),O(1) */ class Solution { int trap(int[] height) { 阅读全文
posted @ 2020-09-26 19:30 SSunSShine 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 5. 26_删除排序数组中的重复项 /* 给定 nums = [0,0,1,1,1,2,2,3,3,4], 函数应该返回新的长度 5, 并且原数组 nums 的前五个元素被修改为 0, 1, 2, 3, 4。 你不需要考虑数组中超出新长度后面的元素。 */ class Solution { publ 阅读全文
posted @ 2020-09-26 19:28 SSunSShine 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 4. 16_最接近的三数之和 /* 输入:nums = [-1,2,1,-4], target = 1 输出:2 解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。 */ class Solution { public int threeSumClosest(int[] 阅读全文
posted @ 2020-09-26 19:27 SSunSShine 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 3. 15_三数之和 /* 给定数组 nums = [-1, 0, 1, 2, -1, -4], 判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ? 满足要求的三元组集合为: [ [-1, 0, 1], [-1, -1, 2] ] */ class Solutio 阅读全文
posted @ 2020-09-26 19:26 SSunSShine 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 2. 11_盛最多水的容器 class Solution { public int maxArea(int[] height) { int i = 0, j = height.length-1, res = 0; while(i < j){ int h = Math.min(height[i],he 阅读全文
posted @ 2020-09-26 19:25 SSunSShine 阅读(62) 评论(0) 推荐(0) 编辑