自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(151)
  • 资源 (1)
  • 收藏
  • 关注

原创 PAT 1104. Sum of Number Segments (20)

Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3)

2016-03-08 11:18:48 593

原创 LeetCode || 198. House Robber

198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them

2016-02-24 20:41:20 493

原创 LeetCode || 299. Bulls and Cows

299. Bulls and CowsYou are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a gu

2016-02-24 20:13:55 981

原创 LeetCode ||326. Power of Three

326. Power of ThreeGiven 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?方法一:循环的方法,最直观简单。耗时128ms.clas

2016-02-24 16:49:21 631

原创 LeetCode || Move Zeroes

Move Zeroes题目链接:Move ZeroesGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1,

2016-02-24 16:27:02 381

原创 LeetCode || Nim Game

Nim Game基本思想: 题目大致意思是:总共有N个球,A首先拿多少个球,然后B拿多少个球,单次拿球数量为1——3个之间,判断N为多少时A球必定能赢。 这道题目的类似版本在很多公司面试中出现。 主要是运用每次A拿m(1<=M<=3)个球,然后B拿4-m个球的思想来处理。 那么,可以轻松将这道题目转变为,当总球数量N为能被4整除时,则B必定会赢,反之A会赢。

2016-02-24 16:13:53 300

原创 Job List

继续~

2015-12-10 21:19:59 786

原创 LeetCode || First Bad Version

// Forward declaration of isBadVersion API.bool isBadVersion(int version);class Solution {public:int firstBadVersion(int n) { if (n <= 1) return n; int i = 1, j = n; int mid = i / 2 + j / 2;

2015-09-11 17:14:08 249

原创 LeetCode || Factorial Trailing Zeroes

class Solution {public: int trailingZeroes(int n) { //找到所有的5 int num = 0; while(n) { num += n/5; n = n / 5; } return num;

2015-09-11 12:34:11 240

原创 LeetCode ||Number of Digit One

class Solution {public: int countDigitOne(int n) { if(n <=0) return 0; int ifac = 1; int front = 0; int back = 0; int curr =

2015-09-11 12:30:43 447

原创 LeetCode || Majority Element II

class Solution {public: vector majorityElement(vector& nums) { //每次取出来三个数,如果三个数均不相同,则都删除。 if(nums.size() < 2) return nums; //找到数组中出现次数大于等于n/3

2015-09-11 11:21:28 262

原创 LeetCode || N-Queens II

使用全排列的思路,效率很低。class Solution {public: bool QueenOrderOK(const vector& q) { for(int i = 0 ;i<q.size();i++) { for(int j = i+1;j<q.size();j++) {

2015-09-08 20:05:24 261

原创 LeetCode || Binary Tree Paths

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-09-08 19:20:22 254

原创 LeetCode || Maximal Square

class Solution {public: int maximalSquare(vector>& matrix) { int row = matrix.size(); if(row == 0) return 0; int col = matrix[0].size(); int i

2015-09-08 16:37:25 302

原创 LeetCode || Maximal Rectangle

class Solution {public: int maximalRectangle(vector>& matrix) { int row = matrix.size(); if(row == 0) return 0; int col = matrix[0].size(); in

2015-09-08 15:37:43 254

原创 LeetCode || Set Matrix Zeroes

class Solution {public: void setZeroes(vector>& matrix) { if(matrix.size() ==0 || matrix[0].size() == 0) return; int row = matrix.size(), col = matri

2015-09-08 12:00:34 269

原创 LeetCode ||Insertion Sort List

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* in

2015-09-08 11:14:48 258

原创 LeetCode || Gray Code

class Solution {public: vector grayCode(int n) { int size = 1 << n; vector r; for(int i = 0;i<size;i++) { int tmp = i^(i>>1); r.push_back(t

2015-09-08 09:41:20 231

原创 LeetCode || N-Queens

使用全排列的方法做的,效率超低的,104ms.class Solution {public: bool CheckNQueuesOK(const vector& queen) { int len = queen.size(); for(int i = 0;i<len;i++) { for(int j =

2015-09-07 12:13:16 318

原创 LeetCode || Permutations

class Solution {public: void permutation(vector& nums, int start, vector>& permu) { if(start == nums.size()) { permu.push_back(nums); } f

2015-09-07 11:55:40 322

原创 LeetCode || Valid Number

//这道题目最麻烦的是:// 1.判断空格应该出现在哪里?// 2.什么样子的数字是有效数字。class Solution {public: int scanDigits(string s, int start, bool& flag)//扫描数字,flag标志是否有扫描到数字,返回string指针的索引 { while(start =

2015-09-05 20:42:26 290

原创 LeetCode || Missing Number

比较简单的算法,直接使用累加求和来实现。class Solution {public: int missingNumber(vector& nums) { int add = 0; for(int i = 0;i<nums.size();i++) { add+=nums[i]; }

2015-09-05 19:21:26 266

原创 LeetCode || Sliding Window Maximum

class Solution {public: vector maxSlidingWindow(vector& nums, int k) { deque index; vector maxValue; if(nums.size() < k || k <=0) return maxValue;

2015-09-05 19:09:53 316

原创 LeetCode ||Remove Duplicates from Sorted Array II

class Solution {public: int removeDuplicates(vector& nums) { if(nums.size() <= 2) return nums.size(); int i = 1; int pre = nums[0];

2015-09-05 18:25:36 303

原创 LeetCode || Reverse Integer

class Solution {public: int reverse(int x) { int positive = 1; if(x < 0) { positive = -1; x *=(-1); } unsigned int revers

2015-09-05 18:07:35 297

原创 LeetCode || Reverse Words in a String

class Solution {public: void reverse(string& str, int s, int e) { if(s > e) return; for(int i = s;i<=(s+e)/2 ;i++) { char tmp = str[i]

2015-09-05 17:54:28 290

原创 LeetCode || Search for a Range

使用二分查找算法,但是遇到求解范围的时候遇到瓶颈。先用顺序搜索求解。时间:20ms。class Solution {public: vector searchRange(vector& nums, int target) { int i = 0, j = nums.size()-1; int mid = (i+j)/2;

2015-09-05 11:28:26 318

原创 LeetCode || Search a 2D Matrix II

class Solution {public: bool searchMatrix(vector>& matrix, int target) { int row = matrix.size(); if(row == 0) return false; int col = matrix[0].size();

2015-09-05 11:15:52 277

原创 LeetCode || Valid Anagram

class Solution {public: bool isAnagram(string s, string t) { if(s.size() != t.size()) return false; int bVisited[30] = {0}; for(int i = 0

2015-09-05 10:52:47 256

原创 LeetCode || Lowest Common Ancestor of a Binary Tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-09-05 10:28:23 263

原创 LeetCode || Lowest Common Ancestor of a Binary Search Tree

Lowest Common Ancestor of a Binary Search Tree Total Accepted: 21201 Total Submissions: 56036My SubmissionsQuestion Solution Given a binary search tree (BST), find the lowest com

2015-09-05 09:30:59 371

原创 LeetCode ||Ugly Number II

class Solution {public: int nthUglyNumber(int n) { if(n <= 0) return 0; int nthNum = 1; int i2= 0, i3 = 0, i5 = 0; vector nums; nums.push_back(1);

2015-09-04 21:48:43 747

原创 LeetCode || Ugly Number

class Solution {public: bool isUgly(int num) { if(num <= 0) return false; while(num%2==0) num = num/2; while(num%3 == 0) num = num/3;

2015-09-04 21:02:03 196

原创 LeetCode || Single Number III

class Solution {public: int GetExclusiveOr(const vector& nums) { int Yihuo = 0; for(int i = 0;i<nums.size();i++) { Yihuo = Yihuo^nums[i]; }

2015-09-04 20:54:43 425

原创 LeetCode || Add Digits

class Solution {public: int addDigits(int num) { int n = num; while(n/10 != 0) { int t = 0; while(n != 0) { t+=n%10;

2015-09-04 20:24:04 366

原创 LeetCode || Combinations

class Solution {public: vector> combine(int n, int k) { vector v; vector> vc; if(k > n || k < 1) return vc; for(int i = 1;i<=k;i++) {

2015-09-04 10:15:56 269

原创 LeetCode: Clone Graph

Clone GraphClone an undirected graph. Each node in the graph contains a label and a list of its neighbors.耗时:84ms。OJ's undirected graph serialization:Nodes are labeled uniquely.

2015-08-14 17:46:28 388

原创 LeetCode: Copy List with Random Pointer

Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy o

2015-08-14 15:57:32 383

原创 LeetCode || Sum Root to Leaf Numbers

Sum Root to Leaf Numbers /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), le

2015-07-29 20:43:20 298

原创 LeetCode || Path Sum II

Path Sum II耗时:16msGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22,

2015-07-29 20:25:26 289

深入浅出mfc(中文)

该文章提供Mfc编程技术。深入浅出的介绍了Mfc编程方式,适合初学mfc者学习,大家可以看看这个中文版的哦。

2012-04-13

空空如也

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

TA关注的人

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