
LeetCode
文章平均质量分 71
Coding_Reading
待我编码有成 娶你为妻可好
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode6. ZigZag Conversion
easy程度题 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N原创 2016-10-27 20:48:40 · 515 阅读 · 0 评论 -
leetcode151. Reverse Words in a String
medium程度题 题目: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". 难度在于给定字符串中空格连续出现的次数不限定 如Given s = " I lov原创 2017-02-24 23:07:33 · 443 阅读 · 0 评论 -
leetcode81. Search in Rotated Sorted Array
medium题 题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value原创 2017-03-07 19:23:05 · 380 阅读 · 0 评论 -
leetcode4. Median of Two Sorted Arrays
hard程度题 题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Exam原创 2017-03-10 19:07:39 · 311 阅读 · 0 评论 -
leetcode128. Longest Consecutive Sequence
hard程度题 题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements se原创 2017-03-19 21:16:02 · 408 阅读 · 0 评论 -
leetcode25. Reverse Nodes in k-Group
Hard程度题 题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked lis原创 2017-04-20 15:20:49 · 449 阅读 · 0 评论 -
leetcode141. Linked List Cycle
easy程度题 题目: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 可以建立一个set集合,每次访问一个新节点,如果集合中没有则将节点放入set, 如果有则说明存在环。不占用额外空间,想不出来原创 2017-04-22 10:18:07 · 360 阅读 · 0 评论 -
leetcode143. Reorder List
medium程度题 题目: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given {1,2,原创 2017-04-22 12:53:52 · 335 阅读 · 0 评论 -
leetcode125. Valid Palindrome
easy程度题 题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "rac原创 2017-04-23 12:32:03 · 339 阅读 · 0 评论 -
leetcode28. Implement strStr()
easy程度题 题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 字符串匹配,暴力匹配复杂度O(M * N) AC解: class Solution { public原创 2017-04-24 09:51:34 · 420 阅读 · 0 评论 -
leetcode8. String to Integer (atoi)
medium程度题 题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are t原创 2017-04-25 10:47:58 · 349 阅读 · 0 评论 -
leetcode 96. Unique Binary Search Trees
题目: 思路: 以k为根节点的树,左子树为【1,…,K - 1】,右子树为【K + 1,…,N】,定义f(n)为【1,…,n】能产生不同的二叉搜索树的个数,则以K为根节点能产生f(k - 1) * f(n - k)种不同的树。显然f(0) = f(1) = 1。 f(2) = f(0) * f(1) + f(1) * f(0) f(3) = f(0) * f(2) + f(1) * f(1)原创 2017-06-04 23:04:36 · 298 阅读 · 0 评论 -
Morris二叉树遍历算法
Morris二叉树遍历算法 时间复杂度O(N),空间复杂度O(1) 这种方法借鉴了线索化二叉树的思想,但是不占用空间中序遍历方法如下: 如果当前节点的左孩子为空,则输出当前节点并将其右孩子作为当前节点。 如果当前节点的左孩子不为空,在当前节点的左子树中找到当前节点在中序遍历下的前驱节点。a) 如果前驱节点的右孩子为空,将它的右孩子设置为当前节点。当前节点更新为当前节点的左孩子。b) 如果前驱节点转载 2017-05-19 23:36:16 · 386 阅读 · 0 评论 -
leetcode100. Same Tree
easy程度题Q: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. 判断两个二叉树是否原创 2017-05-20 16:34:24 · 380 阅读 · 0 评论 -
leetcode101. Symmetric Tree
Q:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:1 / \ 2 2 / \ / \ 3 4 4 3But the原创 2017-05-20 16:17:18 · 391 阅读 · 0 评论 -
leetcode165. Compare Version Numbers
Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.原创 2017-01-25 23:28:02 · 368 阅读 · 0 评论 -
leetcode190. Reverse Bits
easy题 题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in bin原创 2017-01-13 21:14:35 · 475 阅读 · 0 评论 -
leetcode438. Find All Anagrams in a String
1.题目 Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not原创 2016-10-28 19:58:27 · 578 阅读 · 0 评论 -
leetcode26. Remove Duplicates from Sorted Array
从已排好序的数组中去除重复的原创 2017-02-26 21:30:53 · 294 阅读 · 0 评论 -
leetcode414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2,原创 2016-10-26 23:16:37 · 562 阅读 · 0 评论 -
leetcode260. Single Number III
先说第一种题 题目: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it原创 2017-04-09 20:00:20 · 368 阅读 · 0 评论 -
leetcode134. Gas Station
medium程度题 题目: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel原创 2017-04-07 16:07:15 · 401 阅读 · 0 评论 -
leetcode92. Reverse Linked List II
medium程度 题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Giv原创 2017-04-12 22:15:08 · 416 阅读 · 0 评论 -
leetcode36. 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 partia原创 2017-03-31 23:25:20 · 344 阅读 · 0 评论 -
leetcode1. Two Sum
Easy程度题: 题目: 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 you原创 2017-03-20 14:22:52 · 352 阅读 · 0 评论 -
leetcode15. 3Sum
medium程度题 题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution原创 2017-03-21 20:31:08 · 303 阅读 · 0 评论 -
leetcode31. Next Permutation
medium程度题 题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as原创 2017-03-27 21:05:40 · 550 阅读 · 0 评论 -
leetcode60. Permutation Sequence
medium程度题 题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): "1原创 2017-03-28 22:31:26 · 354 阅读 · 0 评论 -
leetcode42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2017-03-31 23:20:39 · 288 阅读 · 0 评论 -
leetcode7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before c原创 2017-01-09 19:29:05 · 345 阅读 · 0 评论 -
leetcode9. Palindrome Number
判断一个整数是否是回文数原创 2017-01-12 18:50:03 · 545 阅读 · 0 评论 -
leetcode 76. Minimum Window Substring
题目: 难度: hard思路: O(n)复杂度下感觉要用哈希表,使用两个指针,指向进行的首尾,当发现有包含T字符串的序列时,移动首指针,缩小氛围,大体思路是这样,但是具体细节和代码实现写不出来-,-。 再读懂了其他解答的情况下实现了代码AC解:class Solution { public: string minWindow(string s, string t) { //原创 2017-08-01 16:11:29 · 526 阅读 · 1 评论