自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [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 326

原创 [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 298

原创 [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 385

原创 [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 398

原创 [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 295

原创 [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 309

原创 [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 374

原创 [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 403

原创 [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 308

原创 [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 357

原创 [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 283

原创 [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 308

原创 [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 314

原创 [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 257

原创 [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 293

原创 [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 512

原创 [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 582

原创 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 390

原创 [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 353

原创 [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 1478

原创 [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 470

原创 [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 720

空空如也

空空如也

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

TA关注的人

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