自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(159)
  • 收藏
  • 关注

原创 Top K Frequent Elements

Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number

2016-05-11 10:18:01 455

原创 [LeetCode]Integer Break

Integer BreakGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For exampl

2016-04-19 14:54:46 895

原创 [LeetCode]LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2016-04-18 20:20:51 450

原创 [LeetCode]Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without

2016-04-18 16:08:38 357

原创 [LeetCode]Repeated DNA Sequences

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri

2016-04-18 16:03:02 391

原创 [LeetCode]Clone Graph

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each

2016-04-17 21:32:15 329

原创 [LeetCode]Word Ladder II

Word Ladder II   Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one lette

2016-04-17 19:06:25 415

原创 [LeetCode]Basic Calculator

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em

2016-03-30 13:52:57 318

原创 [LeetCode]Insertion Sort List

Sort a linked list using insertion sort.写个子函数把最后一个节点插入到合适的位置。注意每次插入后链表值改变了。class Solution {public: ListNode* insertionSortList(ListNode* head) { if(head == nullptr) return nul

2016-03-29 17:07:09 287

原创 [LeetCode]H-Index II

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?对排好序的求H index,可以想到采用Binary Search。把搜寻规则稍微改一下。class Solution {public: int

2016-03-29 14:33:42 376

原创 [LeetCode]H-Index

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikipedia: "A

2016-03-29 13:21:02 383

原创 [LeetCode]Different Ways to Add Parentheses

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +,- and *.Example 1I

2016-03-28 14:23:13 286

原创 [LeetCode]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

2016-03-27 12:58:44 301

原创 [LeetCode] House Robber III

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour

2016-03-26 17:08:59 363

原创 [LeetCode]Maximum Product of Word Lengths

Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le

2016-03-26 16:19:06 394

原创 [LeetCode]Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm sho

2016-03-26 14:08:57 298

原创 [LeetCode]Single Number III

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given 

2016-03-26 14:00:04 343

原创 [LeetCode]Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.参考https://en.wikipedia.org/wiki/Sieve_of_Eratosthenesclass Solution {public: int countPrimes(int n

2016-03-26 10:51:08 274

原创 [LeetCode]Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.利用之前完成的link 翻转。首先找到中间节点,然后对后半link翻转和前半段对比。如果一样说明link是回文。/** * Definition for singly-linked list. * struct ListNode { * int val;

2016-03-26 10:25:33 301

原创 [LeetCode]Binary Tree Paths

Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]中序遍

2016-03-25 20:41:46 306

原创 [LeetCode]Ugly Number

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc

2016-03-25 20:09:43 249

原创 [LeetCode]Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on

2016-03-25 19:55:02 284

原创 [LeetCode]Palindrome Pairs

Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.Example 1:Give

2016-03-25 19:38:41 498

原创 [LeetCode]Count of Range Sum

Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),

2016-03-25 18:20:11 573

原创 C++ String类的实现

训练下实现String类。要完全写好还是有很多细节要注意的。#include #includeclass string{ friend std::ostream& operator<<(std::ostream& os,const string &a);//必须声明为友元函数,不是成员函数,返回的是ostream对象 friend std::istream& operat

2016-03-08 22:06:04 378

原创 [LeetCode]Increasing Triplet Subsequence

Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i, j, k such that arr[i] ar

2016-03-04 10:45:06 347

原创 [LeetCode]Self Crossing

You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south,x[3] metres to the east and so

2016-03-03 20:19:44 1469

原创 [LeetCode]Longest Increasing Path in a Matrix

Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside

2016-03-02 14:31:05 454

原创 [LeetCode]Surrounded Regions

Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X

2016-03-01 23:29:06 638

原创 Implement Trie (Prefix Tree)

mplement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.关于前缀树的知识见https://en.wikipedia.org/wiki/Trie因为题目中说道字母在

2016-02-29 13:53:35 344

原创 将博客搬至CSDN

把LeetCode Solution搬到博客园啦~~欢迎小伙伴有空来坐坐。博客园地址

2015-12-31 14:36:17 318

原创 [LeetCode]Populating Next Right Pointers in Each Node II

Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant

2015-12-30 15:17:23 348

原创 [LeetCode]Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2015-12-30 13:49:11 440

原创 [LeetCode]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-29 16:33:37 323

原创 [LeetCode]Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.递归实现/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tree

2015-12-29 15:49:05 317

原创 [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree.由树的前序遍历和中序遍历来构建子树。首先找到根节点,然后递归找到左侧和右侧根节点完成。/** * Definition for a binary tree node. * struct TreeNode { * int val

2015-12-29 15:29:07 384

原创 [LeetCode]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-12-26 17:15:28 266

原创 [LeetCode]Interleaving String

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r

2015-12-26 14:29:19 265

原创 [LeetCode]Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr

2015-12-26 14:19:51 332

原创 [LeetCode]Remove Duplicates from Sorted Array II

Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi

2015-12-19 20:47:47 344

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除