- 博客(27)
- 资源 (5)
- 收藏
- 关注
原创 LeetCode 148: Sort List (链表排序)
Sort a linked list in O(n log n) time using constant space complexity. 分析:题目要求对链表进行排序,如果采用插入、冒泡等排序方式,则时间复杂度将是O(n*n),达不到题目要求的O(n log n)的要求。O(n log n)复杂度的有快排和归并排序,对于链表来说,归并排序更适合一点。这样题目转换为将一个链表拆分成两...
2015-05-07 22:34:53 617
原创 LeetCode 219:Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.
2015-05-31 18:41:22 4176 1
原创 LeetCode 217:Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is
2015-05-31 18:37:10 7572
原创 LeetCode 23: Merge K Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.本题在上一题(LeetCode 21: Merge Two Sorted Lists)基础上再加深了一步,链表个数从两个改为K个。此题有如下几种解法:1、最简单的方法莫过于每次
2015-05-31 02:04:42 4171
原创 LeetCode 103:Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary
2015-05-31 00:34:47 2621
原创 LeetCode 107: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-05-31 00:11:23 4296
原创 LeetCode 101: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-05-31 00:02:15 632
原创 LeetCode 21:Merge Two Sorted Lists
LeetCode 21: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.题目分析:对两个
2015-05-27 23:08:48 4582
原创 LeetCode 215:Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, return 5.
2015-05-27 00:11:33 3748
原创 LeetCode 145:Binary Tree Postorder Traversal(后序遍历)
Given a binary tree, return the postorder traversal of its nodes' values.
2015-05-23 01:38:46 1437
原创 LeetCode 105:Construct Binary Tree from Preorder and Inorder Traversal
LeetCode 105:Given preorder and inorder traversal of a tree, construct the binary tree.给定一个二叉树的前序和中序遍历,重建这棵二叉树。
2015-05-20 23:09:41 1566
原创 LeetCode 165: Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and cont
2015-05-19 12:28:18 2371
原创 LeetCode 160 :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-05-14 22:06:04 2275
原创 LeetCode 100: 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-05-14 12:46:24 775
原创 LeetCode 104: 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.分析;此题是求二叉树的深度,(无所谓最大深度),用递归的方法很容
2015-05-14 12:43:53 868
原创 LeetCode 136:Single Number I
Single NumberGiven 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 imple
2015-05-12 19:51:37 4272
原创 LeetCode 5: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.分析:采用中心扩展法,每
2015-05-12 00:38:14 3223
原创 LeetCode 190 :Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2015-05-11 23:18:48 1766
原创 LeetCode 191: Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 0000000000...
2015-05-09 13:35:38 503
原创 LeetCode 203: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 --> 5Credits:Special thank
2015-05-08 23:43:43 448
原创 LeetCode 205:Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-05-08 23:06:25 3782
原创 LeetCode 206:Reverse Linked List
Reverse a singly linked list.单向链表的翻转,代码如下: ListNode* reverseList(ListNode* head) { if(head == NULL || head->next == NULL) return head; ListNode Result(0);
2015-05-08 22:36:06 2467
原创 LeetCode 202: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-05-08 22:12:21 2245
原创 LeetCode 204:Count Primes
Description:Count the number of prime numbers less than a non-negative number, n分析:题目要求计算小于N的所有素数的个数。所有主程序很简单:判断是否是素数字,如是,count++ (暂且忽略prim_vec, 后面判断素数时会用到): int countPrimes(int n) {
2015-05-08 18:40:26 4035
原创 LeetCode147: Insertion Sort List
Sort a linked list using insertion sort.本题很简单,用插入排序方法对链表进行排序。可以构建一个临时的链表,然后将待排序的链表的每一个节点插入到临时链表中。代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val; *
2015-05-04 19:24:19 1349
原创 Leetcode 151:Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in
2015-05-03 01:01:01 694
原创 Leetcode 150:Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1"
2015-05-02 15:57:11 560
效能桌面便签V1.66
2010-10-18
FsCapture 6.7 for Windows
2010-10-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人