自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

~心有所依~ 的博客

因为喜欢,所以追求。。。

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

原创 C++容易被忽略的法则

本文主要针对 C++ 中一些最常见惯例和 bug 进行描述。1、构造函数1.1 初始化和赋值C++ 中当一个对象被创建时,会有初始化的操作;而赋值是用来修改一个已经存在的对象的值,此时没有任何新对象的产生。Object t = x; // 初始化,有新对象的产生t = x; // 赋值,对已有对象的值进行修改初始化出现在构造函数中,而赋值出现在 operator

2015-09-07 16:58:18 545

原创 奇偶排序

实现排序函数,对一个整形序列进行排序,要求奇数在前,偶数在后。 如序列 1,2,3,4,5,6,排序后为 1,3,5,2,4,6。 函数原型:void sort(int src[], int len);法 1:先将数组放在一个 vector 中,然后对 vector 整体进行排序,然后扫描两边,第一遍找出所有奇数,按数序放入 src 中,第二遍只找偶数,按数序放在奇数之后。此法需要额外的空间,当

2015-08-21 11:00:38 549

原创 Go 函数

函数是构建 Go 程序的主要成分。其定义如下形式:func (recvarg type) funcname(arg int) (ret1[, ret2] int) { return 0[,0] }关键字 func 用于定义一个函数;recvarg 用于指定此函数可用于的类型,即该类型的方法。funcname 为函数名;arg 为函数参数,函数为值传递;ret 为函数命名返回值,也可以只有类型而不命名

2015-08-15 16:08:32 2223

原创 Go 并发

goroutine 是 Go 并发能力的核心要素。但是,goroutine 到底是什么?叫做 goroutine 是因为已有的短语 — 线程、协程、进程等等 — 传递了不准确的含义。 goroutine 有简单的模型:它是与其他 goroutine 并行执行的,有着相同地址空间的函数。它是轻量的,仅比分配栈空间多一点点消耗。而初始时栈是很小的,所以它们也是廉价的,并且随着需要在堆空 间上分配(和释

2015-08-13 21:42:48 738

原创 Go 方法、接口

在 Go 中,类型可以定义接收此类型的函数,即方法。每个类型都有接口,意味着对那个类型定义了方法集合。下面定义了结构体类型 S 以及它的两个方法:type S struct { i int }func (p *S) Get() int { return p.i }func (p *S) Put(v int) { p.i = v }方法方法就是有接收者的函数。可以在除了非本地类型(包括内建类型,比

2015-08-13 10:16:57 799

原创 Go 控制结构

在 Go 中只有很少的几个控制结构 。这里没有 do 或者 while 循环,只有 for。有(灵活的) switch 语句和 if,而 switch 接受像 for 那样可选的初始化语句。还有叫做类型选择和多路通讯转接器的 select。同 C 相比语法有所不同:无需圆括号,而语句体必须总是包含在大括号内。

2015-08-11 18:40:08 520

原创 Go 数据类型(续)— array、slice、map

Go 将常用的数据结构数组(array)、切片(slices)、映射(map)实现为内置类型。可以利用 array 在列表中进行多个值的排序,或者使用更加灵活的:slice。字典或哈希类型同样可以使用,在 Go 中叫做 map。1、array数组定义array 定义 [n]<type> ,n 为数组长度,长度是类型的一部分,定义后不能改变数组大小;<type> 为数组元素类型,对数组的存取和 C

2015-08-11 15:27:39 680

原创 Go 基础之数据类型、变量

Go 是一种类 C 语言,大部分语法和 C 类似。一、第一个 go 程序,Hello world。package mainimport "fmt" // 实现格式化的 I/O/* Print something */func main() { fmt.Printf("Hello, world\n")}在不引起语义混淆的情况下,Go 可以省略句末的分号,编译器会在每句末尾自动加上分号;并

2015-08-01 16:06:04 453

原创 Golang 简介及配置

Go 是 2009 年发布的一种简单的并行开发,且跨平台的类 C 语言。由于其强大的并行性,很适合用于网络开发中。来自其网站的介绍:Go 编程语言是一个使得程序员更加有效率的开源项目。 Go 是有表达力、简洁、清晰和有效率的。它的并行机制使其很容易编写多核和网络应用,而新奇的类型系统允许构建有弹性的模块化程序。 Go 编译到机器码非常快速,同时具有便利的垃圾回收和强大的运行时反射。它是快速的、静态类

2015-07-31 22:35:54 553

原创 LeetCode 之 Delete Node in a Linked List — C++ 实现

Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and yo

2015-07-27 17:30:23 349

原创 浅谈 malloc/free 和 new/delete

malloc 和 free 是 C 语言中的函数,也可以用在 C++ 中,但在 C++ 中却视为不安全的内存操作。而 new 和 delete 是 C++ 中的两个运算符,完全可以替代 malloc/free 完成内存的操作,且为安全的内存操作。它们的区别有以下几点:malloc / free 为 C/C++ 标准库函数,而 new/delete 为 C++中的运算符。new 创建的对象有类型,

2015-07-25 21:50:17 288

原创 C/C++兼容性

C/C++兼容性C 语言为面向过程的编程语言,C++ 是面向对象的编程语言,有些人也称 C++ 为“带类的 C”。

2015-07-25 18:31:54 1566

原创 LeetCode 之 Implement Queue using Stacks — C++ 实现

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

2015-07-11 18:08:52 771

原创 LeetCode 之 Kth Largest Element in an Array — C++ 实现

Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,

2015-07-11 17:37:55 438

原创 LeetCode 之 Palindrome Linked List — C++ 实现

Palindrome Linked List Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?给定一个单链表,判断是不是回文。追问:可否实现时间复杂度为 O(n),空间复杂度为 O

2015-07-10 21:34:17 643

原创 LeetCode 之 Populating Next Right Pointers in Each Node I II — C++ 实现

Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate

2015-07-04 20:37:44 343

原创 LeetCode 之 Largest Number — C++ 实现

Largest Number Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.N

2015-06-19 17:58:13 463

原创 LeetCode 之 Two Sum — C++ 实现

Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to th

2015-06-19 16:55:29 414

原创 LeetCode 之 Evaluate Reverse Polish Notation — C++ 实现

Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expre

2015-06-19 16:15:29 567

原创 LeetCode 之 Merge Intervals — C++ 实现

Merge IntervalsGiven 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].给定一个区间集合,合并所有重复区间。例如,给定 [

2015-06-19 11:42:05 565

原创 LeetCode 之 Palindrome Number — C++ 实现

Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.确定一个整数是不是回文。要求空间复杂度为O(1).负数不是回文分析:    首先计算正数是 10 的几次幂,然后分别取最高位和最低位比较,如果不相等则不是回文,相等则去掉最高位和最低位继

2015-06-14 14:24:28 505

原创 LeetCode 之 Reverse Integer — C++ 实现

Reverse Integer Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321将一个整数按数字翻转。分析:    每次取数字的最低位作为翻转后整数的最高位,计算时就要进行溢出判断,为防止溢出用 long long i

2015-06-14 14:16:24 276

原创 LeetCode 之 Intersection of Two Linked Lists — C/C++ 实现

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

2015-06-13 17:52:55 334

原创 LeetCode 之 Insertion Sort List — C++ 实现

Insertion Sort List Sort a linked list using insertion sort.对链表使用插入排序。class Solution {public: ListNode* insertionSortList(ListNode* head) { if(!head) { ret

2015-06-13 17:49:42 277

原创 LeetCode 之 Linked List Cycle I II — C++ 实现

Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?给定一个链表,验证是否存在环。附加:能否不额外分配空间。分析:    维护两个指针,ne 每次移动两个节点

2015-06-13 17:33:55 369

原创 LeetCode 之 Partition List — C++ 实现

Partition ListGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of

2015-06-13 17:20:06 266

原创 LeetCode 之 Remove Duplicates from Sorted List I II — C++ 实现

Remove Duplicates from Sorted ListGiven 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, retu

2015-06-13 17:08:03 317

原创 LeetCode 之 Remove Nth Node From End of List — C++ 实现

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 r

2015-06-13 16:55:50 273

原创 LeetCode 之 Merge Two / k Sorted Lists — C/C++ 实现

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.将两个有序链表合并并返回新的链表。新链表是由原链

2015-06-13 16:36:43 332

原创 LeetCode 之 Contains Duplicate I II III — C++ 实现

Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should retur

2015-06-11 21:43:24 859

原创 LeetCode 之 Reverse Linked List — C 实现

Reverse Linked List Reverse a singly linked list.翻转链表。struct ListNode* reverseList(struct ListNode* head) { struct ListNode *pre = NULL, *cur = NULL, *ne = NULL; if(head == NULL)

2015-06-11 21:30:48 305

原创 LeetCode 之 Remove Linked List Elements — C 实现

Remove Linked List ElementsRemove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4

2015-06-11 21:25:37 365

原创 LeetCode 之 Number of 1 Bits — C 实现

Number of 1 BitsWrite 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

2015-06-11 21:10:33 262

原创 LeetCode 之 Rotate Array — C++ 实现

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

2015-06-11 20:59:32 258

原创 LeetCode 之 Compare Version Numbers — C 实现

Compare Version Numbers Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the vers

2015-06-11 20:41:37 242

原创 LeetCode 之 Min Stack — C++ 实现

Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the s

2015-06-11 20:34:25 340

原创 LeetCode 之 Reverse Words in a String — C 实现

Reverse Words in a String Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C progra

2015-06-11 20:17:07 353

原创 LeetCode 之 Sort List — C 实现

Sort List Sort a linked list in O(n log n) time using constant space complexity.对链表进行排序,要求时间复杂度为O(nlogn),空间复杂度为 O(1)。分析:    归并排序。struct ListNode* mergeSort(struct ListNode* head)

2015-06-11 19:20:44 295

原创 LeetCode 之 Valid Palindrome — C 实现

Valid PalindromeGiven 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.

2015-06-11 17:59:16 334

原创 LeetCode 之 Pascal's Triangle — C++ 实现

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]]

2015-06-11 17:50:52 491

空空如也

空空如也

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

TA关注的人

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