摘要:
http://oj.leetcode.com/problems/linked-list-cycle/Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:这个问题是面试时很常见的问题,但是要求写代码的比较少。最简单的方法就是两个指针,一个每次走一步,一个每次走两步,等赶上了就说明有环。 1 class Solution { 2 public: 3 bool hasCycle(ListNode *head) { 4 ... 阅读全文
摘要:
http://oj.leetcode.com/problems/longest-valid-parentheses/Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which has leng 阅读全文