LeetCode之旅
文章平均质量分 60
码农少年
这个作者很懒,什么都没留下…
展开
-
Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2015-12-09 16:10:54 · 167 阅读 · 0 评论 -
Longest Palindromic Substring 最长回文
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Soluti原创 2015-12-21 21:27:33 · 231 阅读 · 0 评论 -
Longest Palindromic Substring 最长回文字符串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Solu原创 2015-12-21 21:18:49 · 236 阅读 · 0 评论 -
Valid Sudoku 数独的有效性
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2015-12-04 10:31:49 · 221 阅读 · 0 评论 -
Remove Element 移除元素
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.c原创 2015-12-03 19:07:01 · 314 阅读 · 0 评论 -
Remove Nth Node From End of List 从链表中删除倒数第N的节点
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原创 2015-12-03 16:26:07 · 227 阅读 · 0 评论 -
Valid Parentheses 有效括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2015-12-03 17:18:09 · 134 阅读 · 0 评论 -
Remove Duplicates from Sorted Array 从排序数组中删除重复
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2015-12-03 18:56:25 · 166 阅读 · 0 评论 -
Merge Two Sorted Lists 合并排序列表
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct Lis原创 2015-12-03 18:30:30 · 156 阅读 · 0 评论 -
Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution {public: int strStr(string haystack, string need原创 2015-12-03 19:48:20 · 125 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree 寻找最低共同祖先
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee原创 2015-12-02 09:53:19 · 192 阅读 · 0 评论 -
Reverse Linked List 反转链表
Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solu原创 2015-12-02 10:42:43 · 218 阅读 · 0 评论 -
Valid Anagram 有效的字谜
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass原创 2015-12-02 08:58:26 · 287 阅读 · 0 评论 -
Delete Node in a Linked List 删除链表的一个节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2015-12-02 09:20:32 · 299 阅读 · 0 评论 -
First Bad Version 第一个坏版本
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2015-12-01 11:21:22 · 451 阅读 · 0 评论 -
Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2015-12-04 11:34:03 · 164 阅读 · 0 评论 -
Valid Sudoku 数独的有效性
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2015-12-04 10:33:48 · 162 阅读 · 0 评论 -
Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2015-12-09 09:34:08 · 181 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2015-12-08 15:14:32 · 130 阅读 · 0 评论 -
Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /原创 2015-12-08 14:50:42 · 129 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following原创 2015-12-08 10:52:25 · 146 阅读 · 0 评论 -
Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.递归方式:/** * Definition for a bin原创 2015-12-08 14:57:33 · 133 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, string b) {原创 2015-12-07 15:17:32 · 244 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition for s原创 2015-12-07 15:51:48 · 196 阅读 · 0 评论 -
Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution {pub原创 2015-12-07 10:53:02 · 163 阅读 · 0 评论 -
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tre原创 2015-12-08 15:44:13 · 124 阅读 · 0 评论 -
Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?递归模式很容易想到,但是超时啦。class Solu原创 2015-12-07 15:30:42 · 134 阅读 · 0 评论 -
Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ原创 2015-12-08 15:30:42 · 150 阅读 · 0 评论 -
Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.采用递归算法:/原创 2015-12-08 10:12:39 · 158 阅读 · 0 评论 -
Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2015-12-07 16:09:44 · 145 阅读 · 0 评论 -
Length of Last Word 最后一个单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2015-12-04 15:27:00 · 336 阅读 · 0 评论 -
Move Zeroes 移动0
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you原创 2015-12-01 10:18:40 · 189 阅读 · 0 评论 -
Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint原创 2015-11-30 15:41:48 · 279 阅读 · 0 评论 -
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.查找最长公共前缀。class Solution {public: string longestCommonPrefix(vector& strs) { if (strs.s原创 2015-11-30 09:47:34 · 168 阅读 · 0 评论 -
Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total ar原创 2015-12-11 15:34:48 · 220 阅读 · 0 评论 -
Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.class原创 2015-12-11 15:11:07 · 241 阅读 · 0 评论 -
Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z ->原创 2015-12-10 16:36:21 · 176 阅读 · 0 评论 -
Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * struct TreeNode { * int原创 2015-12-11 16:14:50 · 190 阅读 · 0 评论 -
Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet原创 2015-12-11 16:01:39 · 184 阅读 · 0 评论 -
Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as you ca原创 2015-12-10 17:30:36 · 159 阅读 · 0 评论