Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Try to d...
题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 解题思路: 倒数第几个节点的问题,和剑指offer上的不一样 这个问题:快指针先走n步,然后slow走的节点其实是倒数第n+1个节点,这样方便删除节点。 当让slower和faster同时一起跑时,就不让 faster跑到null了,让他停在上一步,faster.ne...
LeetCode 中关于括号的题目还是比较多的,比如 Valid Parentheses,Valid Parenthesis String,Remove Invalid Parentheses,和 Longest Valid Parentheses 等。大多都是考察如何判断一个括号字符串是否合法,所谓的合法,大致就是左右括号个数要相同,每个右括号前面必须要有对应的左括号,一个比较简单的判断方法就是用一个变量 ...