自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

记录点滴

用代码窥探数字世界 Hello World

  • 博客(41)
  • 收藏
  • 关注

转载 c++ static的作用,以及static对象在类和函数中区别

转自:点击static对象如果出现在类中,那么该对象即使从未被使用到,它也会被构造以及析构。而函数中的static对象,如果该函数从未被调用,这个对象也就绝不会诞生,但是在函数每次被调用时检查对象是否需要诞生。下面详细说说static的功能以及它的来龙去脉:static作为编程语言里面一种重要的数据类型,它的地位在面试的过程里也是相当的高。为什么要引入static

2017-01-19 07:49:38 305

原创 unix环境高级编程 程序3-11(fileflags.c)全面解析

源程序:#include "apue.h"#include intmain(int argc, char *argv[]){ int val; if (argc != 2) err_quit("usage: a.out "); if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0) err_sys("fcntl erro

2017-01-18 11:09:00 791

原创 Github Webbench 源码分析+学习(待续)

前言:Webbench 是一个古老而著名的网站压力测试工具,简单而实用。如果你不清楚你的网站能承受多大的压力,或者你想分析对比两个网站的性能,webbench 再好用不过了。Gitbub 地址:https://github.com/cnnewjohn/webbench1,linux编程学习:Makefile记得以前linux程序都是直接g++编译的(好几行是一个命令

2017-01-16 02:10:24 725

原创 57. Insert Interval , STL的使用

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E

2017-01-07 03:45:34 285

原创 56. Merge Intervals 好代码

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]./** * Definition for an interval. * struct I

2017-01-07 02:00:28 288

原创 54. Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]

2017-01-07 01:02:38 266

原创 50. Pow(x, n) 二分应用的又一经典案例

Implement pow(x, n).需要注意的两点1, 当n为 INT_MIN时: int n = INT_MIN; int a = -n; // a == -22147483648 int b = abs(n);// b == -221474836482,n 右移了多少次, x 翻多少翻,而不是ans翻多少翻,因为还有ans = ans * x;AC 代码:

2017-01-06 23:56:41 385

原创 48. Rotate Image 旋转矩阵的通用方法

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public:/* * clockwise rotate *

2017-01-06 22:42:22 412

原创 42. Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1],

2017-01-06 21:52:03 244

原创 41. First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant

2017-01-06 13:18:12 176

原创 38. Count and Say

The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as 

2017-01-06 11:50:56 203

原创 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-01-06 10:50:20 201

原创 34. Search for a Range 史上最简洁的二分搜索的写法

Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the

2017-01-06 10:22:00 494

原创 33. Search in Rotated Sorted Array 旋转排序数组极值的二分求法

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If foun

2017-01-06 02:56:07 367

原创 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2017-01-06 01:32:28 361

原创 29. Divide Two Integers 每一行都是精炼

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.法一:可以直观的利用除数的倍数,但如果这个倍数很大(题目中要求不能用乘法)则会造成LTE,此法不可行!!!class Solution {public

2017-01-06 00:25:14 241

原创 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-01-05 21:34:38 180

原创 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-01-05 20:37:08 168

原创 25. Reverse Nodes in k-Group 怎样不使用额外空间翻转一个单向链表?

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is

2017-01-05 12:20:19 427

原创 21. Merge Two Sorted Lists 一道基础题的两种精炼解法

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

2017-01-05 09:53:11 944

原创 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-01-05 09:15:48 180

原创 19. Remove Nth Node From End of List 一道简单的双指针

Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the

2017-01-05 03:51:18 260

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

2017-01-05 01:21:24 282

原创 15. 3Sum hash解法 vs 双指针解法

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: The solution set must not contain d

2017-01-05 00:45:30 1136

原创 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 res; int h = strs.s

2017-01-04 12:03:42 365

原创 12. Integer to Roman 13. Roman to Integer 玩转罗马数字

int -> Romanclass Solution {public: string intToRoman(int num) { char* c[4][10]={ {"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","

2017-01-04 11:03:03 287

原创 11. Container With Most Water 双指针问题

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

2017-01-04 10:06:34 212

原创 9. Palindrome Number 多种输入情况的考察

Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of convertin

2017-01-04 08:57:09 219

原创 8. String to Integer (atoi) 对于输入情况的考察

以下几种情况要考虑到1,排除输入空格问题2,确定正负3,排除字母4,处理overflowclass Solution {public: int myAtoi(string str) { if (str.empty()) return 0; int i = 0, sign = 1; while (i + 1 < str.size() && isspace(st

2017-01-04 07:47:49 285

原创 7. Reverse Integer 一个简单但是非常考察思维全面性的题目。

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c

2017-01-04 06:48:25 275

原创 6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I

2017-01-04 03:14:54 220

原创 5. Longest Palindromic Substring 暴力 800ms -> dp 97ms -> 回归原始 3ms AC

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.

2017-01-03 23:54:38 217

原创 2. Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

2017-01-03 20:45:38 212

原创 23. Merge k Sorted Lists 典型的分治,另,合并两个List的好写法

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne

2017-01-03 10:31:25 270

原创 4. Median of Two Sorted Arrays 典型的二分,分治算法, 另 第k小的O(lgk)解法

There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 =

2017-01-02 21:44:04 407

原创 135. Candy 考验逻辑能力的时候到了

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on

2017-01-02 14:20:07 249

原创 134. Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to

2017-01-02 09:18:21 154

原创 79, Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically

2017-01-02 01:26:44 184

原创 55. Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i

2017-01-02 01:20:38 200

原创 93. Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order

2017-01-01 21:11:11 271

空空如也

空空如也

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

TA关注的人

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