LeetCode
IT圈的01羊
这个作者很懒,什么都没留下…
展开
-
LeetCode#206#21#83|链表递归
这几个LeetCode的题目都可以通过递归来解决链表问题,汇总记下。#206反转一个单链表。示例:输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NULL public ListNode reverseList(ListNode head) { //1.递归 //递归结束的条件 if(head == null || head.next == null) return head;原创 2020-07-16 22:35:41 · 104 阅读 · 0 评论 -
LeetCode#19 删除链表的倒数第N个节点|哑结点
题目描述给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。示例:给定一个链表: 1->2->3->4->5, 和 n = 2.当删除了倒数第二个节点后,链表变为 1->2->3->5.说明:给定的 n 保证是有效的。分析目的是要找到目标节点的前一个节点,但是头结点没有前一个节点,因此设置一个哑结点。定义两个指针p和q,p向前移动n+1步后,此时p和q之间正好相隔了n个节点。同时移动两个节点,当p指向链表最后的null时,q正好指向目标原创 2020-07-16 22:24:15 · 120 阅读 · 0 评论 -
LeetCode#680 验证回文字符串Ⅱ|双指针
题目描述给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。示例 1:输入: “aba”输出: True示例 2:输入: “abca”输出: True解释: 你可以删除c字符。注意:字符串只包含从 a-z 的小写字母。字符串的最大长度是50000。分析本题的关键是可以删去一个字符,利用双指针,一个指针从头向尾扫描,一个指针从尾向头扫描。指针扫描过的元素一定是...原创 2020-04-23 17:23:24 · 92 阅读 · 0 评论 -
LeetCode#345 反转字符串中的元音字母|Java HashSet和HashMap|双指针|String字符串和字符数组
1. 知识拓展1.1 HashSet和HashMap1.1.1 HashSetHashSet是实现Set< E >接口的一个实体类,数据以哈希表的形式存放,特点是不允许有重复元素且无序存放元素。既然是实现了Set< E >接口,那Set< E >接口的特性是什么呢?Set接口继承了Collection接口,故包含Collection接口的所有方法。无...原创 2020-04-23 01:17:20 · 239 阅读 · 0 评论 -
LeetCode#633 Sum of Square Numbers平方数之和|双指针
运行结果原创 2020-04-19 23:20:48 · 140 阅读 · 0 评论 -
LeetCode#167 Two Sum II - Input array is sorted两数之和 II - 输入有序数组|双指针
题目描述给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2。说明:返回的下标值(index1 和 index2)不是从零开始的。你可以假设每个输入只对应唯一的答案,而且你不可以重复使用相同的元素。示例:输入: numbers = [2, 7, 11, 15], t...原创 2020-04-18 17:12:24 · 119 阅读 · 0 评论 -
LeetCode#20 Valid Parentheses有效的括号|Java中栈的基本操作
题目描述给定一个只包括 ‘(’,’)’,’{’,’}’,’[’,’]’ 的字符串,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。示例 1:输入: “()”输出: true示例 2:输入: “()[]{}”输出: true示例 3:输入: “(]”输出: false示例 4:输入:...原创 2020-02-25 17:20:58 · 103 阅读 · 0 评论 -
LeetCode#14 Longest Common Prefix最长公共前缀
题目描述编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 “”。示例 1:输入: [“flower”,“flow”,“flight”]输出: “fl”示例 2:输入: [“dog”,“racecar”,“car”]输出: “”解释: 输入不存在公共前缀。说明:所有输入只包含小写字母 a-z 。题目分析将输入的字符串保存在字符串数组中,依次比较...原创 2020-02-24 23:09:41 · 102 阅读 · 0 评论 -
LeetCode#12 Integer to Roman整数转罗马数字
题目描述罗马数字包含以下七种字符: I, V, X, L,C,D 和 M。字符 数值I 1V 5X 10L 50C 100D 500M 1000例如, 罗马数字 2 写做 II ,即为两个并列的...原创 2020-02-21 16:13:02 · 107 阅读 · 0 评论 -
LeetCode#13 Roman to Integer罗马数字转整数
题目描述Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2020-02-21 11:10:00 · 137 阅读 · 0 评论 -
LeetCode#9 Palindrome Number 回文数
题目描述Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: trueExample 2:Input: -121Output: falseExplan...原创 2020-02-20 18:36:59 · 81 阅读 · 0 评论 -
LeetCode#7 Reverse Integer整数反转
题目描述Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing wit...原创 2020-02-18 18:42:18 · 105 阅读 · 0 评论 -
LeetCode#2 Add Two Numbers
题目描述You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and ret...原创 2019-01-01 15:20:30 · 86 阅读 · 0 评论 -
LeetCode#1Two Sum
LeetCode:NO.1Two Sum题目描述Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and ...原创 2018-12-31 11:46:35 · 122 阅读 · 0 评论