自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 169. Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element a

2017-10-19 22:04:08 162

原创 168. Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits:S

2017-10-19 21:56:31 155

原创 167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number

2017-10-19 21:45:35 179

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

2017-10-19 21:29:09 123

原创 155. Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time设置两个栈,一个min存放小数栈顶即为最小的数class MinStack {public:   stack min;   stack sta;  void push(in

2017-10-19 19:27:58 176

原创 141. Linked List Cycle

Given a linked list, determine if it has a cycle in it.class Solution {public:    bool hasCycle(ListNode *head)     {         ListNode* p=head;         ListNode* q=head;        while

2017-10-19 19:18:17 111

原创 136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.class Solution {public:    int singleNumber(vector& nums)       {          int len=nums.siz

2017-10-19 19:03:03 113

原创 125. 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

2017-10-19 17:25:24 124

原创 122. Best Time to Buy and Sell Stock II

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on

2017-10-19 17:17:13 122

原创 121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2017-10-09 19:23:47 135

原创 119. Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].class Solution {public:    vector getRow(int rowIndex)    {     vector las

2017-10-09 18:02:13 165

原创 118. Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solut

2017-10-09 09:29:08 179

原创 112. 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

2017-09-27 11:30:51 146

原创 111. Minimum 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.给定一个二叉树,找到其最小深度这道题与max depth这道

2017-09-27 11:10:06 125

原创 110. Balanced Binary Tree

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe

2017-09-27 10:32:45 195

原创 108. 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; *     TreeNode *l

2017-09-27 10:07:20 120

原创 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,null,null,15,

2017-09-20 22:39:18 151

原创 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.依然采用的思想是递归的方法/** * Definitio

2017-09-20 22:17:43 121

原创 101. Symmetric Tree

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

2017-09-20 22:04:10 120

原创 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.利用递归判断

2017-09-19 20:56:37 285

原创 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add

2017-09-19 20:06:12 254

原创 83. 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.给定一个已经排序好的链表,删除其中的重复元素。

2017-09-19 19:16:05 222

原创 70. Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a posi

2017-09-18 17:32:32 331

原创 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x.计算x的算术平方根class Solution {public:    int mySqrt(int x)     {      double begin(0);      double   end(x)

2017-09-18 16:55:08 379

原创 67. Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".设置一个·carry位,如果两个数按位相加和大于等于2则carry位等于1class Solution {public:    string a

2017-09-18 16:26:26 315

原创 66. Plus One

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digi

2017-09-17 17:07:31 360

原创 58. Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is

2017-09-17 16:59:03 131

原创 53. Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] 

2017-09-17 16:42:16 132

原创 38. Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read

2017-09-17 10:54:31 207

原创 35. Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2017-09-17 10:31:08 142

原创 28. Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.给两个字符串,文本串s以及模式串p,现在要查找p在s中的位置,如果找不到则返回-1.两种解决方案:暴力搜索cla

2017-09-17 09:43:38 155

原创 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2017-09-15 22:33:31 169

原创 26. Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2017-09-15 21:44:06 137

原创 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.合并两个已经排序好的链表。class Solution {public:    ListNode*

2017-09-15 21:20:44 121

原创 20. Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2017-09-14 21:51:08 150

原创 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.class Solution{public:string longestCommonPrefix(vector& strs) {        if(strs.size() == 0)

2017-09-14 21:12:12 115

原创 13. Roman to Integer

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.将罗马数转换为实数,首先要明白罗马数转为实数的规则:可以一次把输入字符串扫描一遍,从第一个字符开始,到最后一个字符为止,一次比较当前字符a和当前字符的下一个字符b。

2017-09-14 20:33:54 147

原创 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.判断一个数是否为回文数。举例说明:1234321取出最左边的数1,最右边的数1,比较相同,首先算得输入数的位数为7位,然后1234321/1000000=1取得1,然后再用1234321%10=1;再将1234321变为(1234321

2017-09-12 21:50:00 120

原创 7. Reverse Integer

7. Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321反转实数思路:首先判断这个数是正数还是负数。如果是负数,则转换为正数,然后加一负号。class solution{public:i

2017-09-12 19:58:35 143

原创 1. Two Sum

刚开始学习C++。试着刷一下Leetcode,第一个月先把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 exactl

2017-09-12 17:55:35 169

空空如也

空空如也

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

TA关注的人

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