leetCode
文章平均质量分 65
朱传林
每个不曾起舞的日子,都是对生命的辜负!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetCode(38):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 betw原创 2015-07-16 14:48:19 · 938 阅读 · 0 评论 -
leetCode(27):Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2015-07-02 09:05:30 · 681 阅读 · 0 评论 -
LeetCode(35):Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2015-07-10 09:26:13 · 746 阅读 · 0 评论 -
leetCode(51):Valid Palindrome
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."race a car" is not a原创 2015-07-25 11:56:07 · 797 阅读 · 0 评论 -
Linux命令学习(28) ln命令
ln 是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在 每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,不必重复 的占用磁盘空间。1.命令格式: ln [参数][源文件或目录][目标文件或目录]转载 2015-07-26 09:45:24 · 643 阅读 · 0 评论 -
leetCode(36):Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota原创 2015-07-13 16:00:36 · 752 阅读 · 0 评论 -
leetCode(32):Power of Two
Given an integer, write a function to determine if it is a power of two. 2的幂的二进制表示中,必然只有一个“1”,且不可能为负数。class Solution {public: bool isPowerOfTwo(int n) { if(n<0) {//若为负数则原创 2015-07-07 10:40:56 · 831 阅读 · 0 评论 -
leetCode(31):Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi原创 2015-07-07 10:23:21 · 715 阅读 · 0 评论 -
leetCode(37):Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(原创 2015-07-14 08:42:07 · 796 阅读 · 0 评论 -
leetCode(52):Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题目并不复杂,以下是我的程序,后面是别人的程序,瞬间low了好大一截!冗长!!!!!!!class Solution {public: s原创 2015-07-28 23:03:32 · 667 阅读 · 0 评论 -
leetCode(22):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-06-22 09:09:43 · 632 阅读 · 0 评论 -
leetCode(17):Minimum/Maximize 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-06-21 16:05:06 · 717 阅读 · 0 评论 -
leetCode(39):Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node原创 2015-07-17 10:03:39 · 794 阅读 · 0 评论 -
leetCode(55):Minimum Window Substring(limits.h头文件)
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN原创 2015-08-09 22:01:01 · 1090 阅读 · 0 评论 -
leetCode(29):Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares原创 2015-07-03 07:55:09 · 643 阅读 · 0 评论 -
leetCode(41):Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.取中间的结点作为根结点即平衡二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; *原创 2015-07-17 17:03:38 · 666 阅读 · 0 评论 -
leetCode(42):Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2015-07-17 18:31:05 · 702 阅读 · 0 评论 -
leetCode(40):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-07-17 16:46:25 · 958 阅读 · 0 评论 -
leetCode(45):Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-07-20 08:34:58 · 780 阅读 · 0 评论 -
leetCode(43):Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O原创 2015-07-19 19:02:36 · 763 阅读 · 0 评论 -
leetCode(44):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-07-19 19:29:47 · 534 阅读 · 0 评论 -
leetCode(47):Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2015-07-22 20:03:03 · 726 阅读 · 0 评论 -
leetCode(46):Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements. 直观地一想,查找第k小的数,不就是原创 2015-07-22 14:28:09 · 903 阅读 · 0 评论 -
leetCode(49):Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.判断一个数是否是质数主要有以下几种方法:1)直接用该数除于所有小于它的数(非0,1),如果均不能被它整除,则其是质数;2)除以小于它一半的数,因为大于其一半必定是无法整除,如果均不能被它整除,则其是质数;原创 2015-07-24 09:58:04 · 844 阅读 · 0 评论 -
leetCode(48):Excel Sheet Column Number And Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 class Soluti原创 2015-07-24 08:51:41 · 735 阅读 · 0 评论 -
leetCode(50):Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].本题我采用的是最直观的算法,但整数转化为字符还有些坎坷。应该还有简单的算法,但目前没有时间去研究了。原创 2015-07-24 11:17:01 · 793 阅读 · 0 评论 -
leetCode(53):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 a原创 2015-08-05 15:25:02 · 633 阅读 · 0 评论 -
leetCode(54):Gas Station
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 from station i to原创 2015-08-06 10:09:39 · 680 阅读 · 0 评论 -
leetCode(19):Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled,原创 2015-06-22 08:32:26 · 927 阅读 · 0 评论 -
leetCode(2):Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition fo原创 2015-06-16 14:40:20 · 665 阅读 · 0 评论 -
leetCode(1):Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ListNode* reverseList(ListNode* he原创 2015-06-16 14:38:15 · 772 阅读 · 0 评论 -
leetCode(5):Sort List
Sort a linked list in O(n log n) time using constant space complexity. 分析:排序算法中,堆排序、归并排序、快速排序、希尔排序的时间复杂度是nlogn,堆排序和归并排序对下标依赖性比较强,比较适合顺序表的排序,对链表处理起来比较复杂。希尔排序用的比较少。所以我选择的是快速排序,结果是正确的,但时间超出限原创 2015-06-17 09:45:06 · 917 阅读 · 0 评论 -
leetCode(3):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-06-16 14:41:33 · 673 阅读 · 0 评论 -
leetCode(4):Insertion Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2015-06-17 09:42:53 · 799 阅读 · 0 评论 -
leetCode(7):Copy list with random pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./** * Definition for singly-l原创 2015-06-18 08:11:07 · 1034 阅读 · 0 评论 -
leetCode(8):merge two sorted list
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 L原创 2015-06-18 08:12:55 · 755 阅读 · 0 评论 -
leetCode(11):Reverse linked list II
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:Given m, n satisfy t原创 2015-06-18 15:16:54 · 661 阅读 · 0 评论 -
leetCode(10):Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2015-06-18 09:08:07 · 848 阅读 · 0 评论 -
leetCode(12):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 f原创 2015-06-18 15:48:45 · 677 阅读 · 0 评论 -
leetCode(13):Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->原创 2015-06-18 16:44:53 · 816 阅读 · 0 评论
分享