自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

我在天上飘的博客

自信的生活态度+学海无涯乐作舟

  • 博客(33)
  • 资源 (1)
  • 收藏
  • 关注

翻译 61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-link

2016-04-28 21:46:30 216

原创 189. Rotate Array数组右移

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as

2016-04-28 16:46:30 204

原创 18. 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element

2016-04-28 15:51:09 197

原创 16. 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2016-04-28 15:19:53 163

转载 15. 3Sum

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c

2016-04-28 10:51:58 153

转载 343. Integer Break

Given 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 example, given n = 2, ret

2016-04-26 10:19:12 187

原创 344. Reverse String

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".class Solution {public: string reverseString(string s) {

2016-04-25 21:54:32 2022

原创 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) { string result; int len =

2016-04-22 10:46:39 197

原创 105. 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; * TreeNode *left; * TreeNode *right

2016-04-21 18:53:18 225

原创 199. Binary Tree Right Side View

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1

2016-04-21 15:51:40 130

原创 116. Populating Next Right Pointers in Each Node

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.

2016-04-21 15:22:35 151

转载 22. Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()

2016-04-21 10:44:01 162

原创 109. Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.【思路】将有序链表转换成有序数组,利用108的递归方法求得。/** * Definition for singly-linked list. * struct ListN

2016-04-20 13:09:32 167

原创 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. * st

2016-04-20 12:51:21 163

原创 213. House Robber II

Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time

2016-04-20 10:57:09 163

转载 337. 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-04-20 10:21:23 180

转载 96. Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \

2016-04-19 15:52:39 141

原创 162. Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in

2016-04-19 15:16:49 137

原创 230. 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.Follow up:What if the

2016-04-19 14:37:55 153

原创 142. Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.【思路】建立一个map,标记是否访问过。如果再次访问,则为环的起点。提示双指针,是什么思路呢?/** *

2016-04-19 11:28:02 130

原创 287. Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,

2016-04-19 10:51:22 183

原创 318. 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-04-19 10:16:24 141

原创 319. Bulb Switcher

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off

2016-04-19 08:53:45 162

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

2016-04-18 22:44:26 143

原创 268. 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-04-18 21:49:42 146

原创 260. 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-04-18 21:34:00 153

原创 137. Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.用map统计次数class Solution {public: int singleNumber(vector& nums) { if(nums.size()<=3

2016-04-18 21:29:02 143

原创 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) { if(nums.size()==1) return n

2016-04-18 20:53:04 173

原创 342. 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:37:54 546

原创 326. Power of Three

Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?class Solution {public: bool isPowerOfThree(int n)

2016-04-18 16:33:07 179

原创 231. Power of Two

Given an integer, write a function to determine if it is a power of two.class Solution {public: bool isPowerOfTwo(int n) { if(n <= 0 ) return false; if(n==1 || n==2) return true;

2016-04-18 16:28:24 142

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

2016-04-18 16:11:07 140

原创 232. 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(

2016-04-18 11:25:27 147

贝叶斯分类方法

将Iris数据集进行分类,利用最大后验估计的贝叶斯方法。Matlab代码。

2015-11-03

空空如也

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

TA关注的人

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