![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 50
探小虎
工作四年经验,在阿里工作三年,目前在蚂蚁集团。
展开
-
LeetCode 2.两数相加
2. 两数相加 给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例 1 : 输入:l1 = [2,4,3], l2 = [5,6,4] 输出:[7,0,8] 解释:342 + 465 = 807. 示例 2: 输入:l1 = [0], l2 = [0] 输出:原创 2021-04-24 22:42:34 · 140 阅读 · 0 评论 -
leetcode刷题目录
动态规划原创 2018-11-21 18:41:11 · 182 阅读 · 0 评论 -
leetcode 168.Excel Sheet Column Title
Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear in an Excel sheet. 1 -> A 2 -> B 3 -> C … 26 -> Z 27 -> AA 28 -> AB 分析:十进制辗除法 packa...原创 2018-11-16 19:12:48 · 126 阅读 · 0 评论 -
LeetCode 53. 最大子序和
最大子序和 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。 思路1: //S(i)=Max(ai,s(i-1)+ai) dp package string; public class Solution ...原创 2018-10-15 17:25:09 · 94 阅读 · 0 评论 -
leetcode 70.爬楼梯
70.爬楼梯 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。 思路1: 爬一阶楼梯只需要一次,爬两阶楼梯需要两次,爬三阶楼梯存在分成两种情况,一种是从一阶爬两此次,一种是从两阶爬一次。 package string; public class Solution { public int c...原创 2018-10-15 11:17:31 · 128 阅读 · 0 评论 -
Leetcode. 20 有效括号
20 有效括号 给定一个只包括 ‘(’,’)’,’{’,’}’,’[’,’]’ 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。 注意空字符串可被认为是有效字符串。 import java.util.Map; import java.util.Stack; public class Solution{ public bool...原创 2018-10-15 10:50:56 · 85 阅读 · 0 评论 -
leetcode 2.两数相加
标题 给定两个非空链表来表示两个非负整数。位数按照逆序方式存储,它们的每个节点只存储单个数字。将两数相加返回一个新的链表。 你可以假设除了数字 0 之外,这两个数字都不会以零开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 /** * Definition fo原创 2018-10-14 01:03:52 · 123 阅读 · 0 评论 -
LeetCode 66. Plus One
一、题目 Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. The digit...转载 2018-10-07 14:14:03 · 93 阅读 · 0 评论 -
leetcode 101. Symmetric Tree
101. Symmetric Tree 给定一个二叉树,检查它是否是它自己的镜子(即,围绕它的中心对称)。 例如,这个二叉树[1,2,2,3,4,4,3]是对称的: For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / 2 2 / \ / 3 4 4 3 /** * Definition for a binar...原创 2018-10-18 01:40:36 · 115 阅读 · 0 评论 -
LeetCode 28. Implement strStr()
28. Implement strStr(). 题目描述: Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 这道题让我们在一个字符串中找另一个字符串第一次出现的位置,那我们首先要做一些判断,如果子字符串为空,则返回0,如果子字符串长度大...原创 2018-10-07 00:07:54 · 107 阅读 · 0 评论 -
88. Merge Sorted Array
归并排序数组 从·nums1的末尾开始对比两个数组的最大值排序 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int len; len=n+m-1; m--; n--; while(n>=0&...原创 2018-07-06 23:01:04 · 73 阅读 · 0 评论 -
404. Sum of Left Leaves
404.Sum of Left Leaves class Solution { public int sumOfLeftLeaves(TreeNode root) { return sumOfLeftLeavesHelper(root, false); } public int sumOfLeftLeavesHelper(TreeNode root...转载 2018-07-04 19:47:21 · 84 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
Find All Numbers Disappeared in an Array class Solution { public List<Integer> findDisappearedNumbers(int[] nums) { List<Integer> list=new ArrayList<>(); fo...转载 2018-07-03 15:13:20 · 83 阅读 · 0 评论 -
1. Two Sum
标题 public class mm { public int[] twoSum(int[] nums, int target) { int []reNum=new int[2]; HashMap<Integer, Integer> map=new HashMap<>(); for(int i=0;i&...原创 2018-06-27 23:37:45 · 81 阅读 · 0 评论 -
141. Linked List Cycle
判断链表是否有环 定义一个快指针和一个慢指针,在环中快指针会追上慢指针。 public boolean hasCycle(ListNode head) { ListNode fast = head; ListNode slow=head; while(fast.next!=null&&fast.next.next!=null) {...原创 2018-07-08 22:53:49 · 69 阅读 · 0 评论 -
Leetcode-Maximize Distance to Closest Person (与最近的那个人的距离)
Maximize Distance to Closest Person 第一次错误答案, 思路,从一个确定做的一个位置,分别得出与其他人的距离。 选取最短的。然后存起来,最大的比对。但是无法去除右边没有1的可能。 public static int maxDistToClosest(int[] seats) { int distance=0; ...原创 2018-06-19 23:34:41 · 715 阅读 · 0 评论 -
697. Degree of an Array 数组的度
数组的度 采用数组这个来记住一个数的出现次数,以及第一次出现和最后一次出现次数。 package leetcode; import java.util.HashMap; public class mm { public static int findShortestSubArray(int[] nums) { HashMap<Integer,int[]&g...原创 2018-06-18 22:31:11 · 181 阅读 · 0 评论 -
Leetcode-67-Add Binary 二进制数相加
Add Binary package leetcode; public class mm { public static String addBinary(String a, String b) { StringBuilder str = new StringBuilder(); //二进制数相加,应从最右边开始! ...原创 2018-06-18 20:12:38 · 125 阅读 · 0 评论 -
Magic Squares In Grid 在网格中的模方
Magic Squares In Grid class Solution { public int numMagicSquaresInside(int[][] grid) { int counter = 0, R = grid.length, C = grid[0].length; for (int i = 0; i < R - 2...转载 2018-06-21 00:20:34 · 158 阅读 · 0 评论