自定义博客皮肤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)
  • 收藏
  • 关注

原创 包含min函数的栈

#include <stack>using namespace std;class Solution {public: void push(int value) { s.push(value); } void pop() { if (!s.empty()) {s.pop();} } int top()

2017-06-09 18:09:37 315

原创 顺时针打印矩阵

class Solution {public: vector<int> printMatrix(vector<vector<int> > matrix) { int direction[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int m = matrix.size(); int n = matr

2017-06-09 18:08:50 245

原创 二叉树的镜像

/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: void

2017-06-09 18:08:18 206

原创 树的子结构

/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: bool

2017-06-09 18:07:36 224

原创 合并两个排序的链表

/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* Merge(ListNode* pHead1, ListNode* p

2017-06-09 18:07:08 218

原创 反转链表

/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* ReverseList(ListNode* pHead) {

2017-06-09 18:06:29 206

原创 链表中倒数第k个结点

/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode FindKthToTail(ListNode head,int k)

2017-06-09 18:06:03 203

原创 调整数组顺序使奇数位于偶数前面

public class Solution { public void reOrderArray(int [] array) { int k = 0; for (int i = 0; i < array.length; i++) { if (array[i] % 2 != 0) { int temp =

2017-06-09 18:05:19 222

原创 数值的整数次方

import java.math.BigDecimal;public class Solution { public double Power(double base, int exponent) { boolean isSub = false; BigDecimal result = new BigDecimal(base+"");

2017-06-09 18:04:34 189

原创 进制中1的个数

public class Solution { public int NumberOf1(int n) { int num = 0; // 负数在计算机中以补码形式存在,补码为原码最高位不变,其余位取反再加1 // ~取反操作符,是连最高位也取反。 // 整数左移在末尾添0,右移在前面添0 // 负数左移在末尾添

2017-06-09 18:04:07 279

原创 矩形覆盖

public class Solution { public int RectCover(int target) { if (target == 0) return 0; if (target == 1) return 1; if (target == 2) return

2017-06-09 18:03:37 194

原创 变态跳台阶

public class Solution { public int JumpFloorII(int target) { int[] array = new int[target+1]; array[0] = 1; array[1] = 1; for(int i = 2; i <= target; i++) {

2017-06-09 18:02:53 321

原创 跳台阶

public class Solution { public int JumpFloor(int target) { if (target == 1) return 1; if (target == 2) return 2; int[] array = new int [target + 1];

2017-06-09 18:02:28 200

原创 斐波拉契数列

public class Solution { public int Fibonacci(int n) { int[] array = new int[40] ; array[1] = 1; array[2] = 1; for (int i = 3; i <= n; i++) array[i] = arr

2017-06-09 18:01:40 294

原创 旋转数组的最小数字

import java.util.ArrayList;public class Solution { public int minNumberInRotateArray(int [] array) { if (array == null || array.length == 0) { return 0; } int m

2017-06-09 18:01:09 193

原创 用两个栈实现队列

import java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { // 入栈数据时,将入栈的数

2017-06-09 18:00:26 173

原创 重建二叉树

/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public

2017-06-09 17:59:55 235

原创 从尾到头打印链表

/*** public class ListNode {* int val;* ListNode next = null;** ListNode(int val) {* this.val = val;* }* }**/import java.util.ArrayList;public c

2017-06-09 17:59:14 189

原创 替换空格

public class Solution { public String replaceSpace(StringBuffer str) { return str.toString().replaceAll(" ", "%20"); }}

2017-06-09 17:58:25 284

原创 二维数组中的查找

public class Solution { public boolean Find(int target, int [][] array) { try { for (int i = 0; i < array.length; i++) { if (array[i][0] > target) { // 如果比array[

2017-06-09 17:57:32 213

原创 C++ 单独编译(原型与实现分离)

将原来的程序分为三个部分:头文件:包含结构声明和使用这些结构的函数原型。源代码文件:包含于结构有关的函数的代码。源代码文件:包含调用与结构相关的函数的代码。头文件常包含的内容:函数原型使用#define 或const定义的符号常量结构声明类声明模板声明内联函数防止重复包含#ifndef NAME_H_#define NAME_H_// place include file

2017-06-04 18:13:05 1034

原创 C++ const相关

一些结论:可以建const变量的地址赋给指向const的指针,但不能将const的指针赋给常规指针// "hello world"为字符串常量,不可被修改,他的值为第一个字符的地址const char * str = "hello world"; // 正确const char * temp = str; // 正确char *temp = str; // 错误非const指针赋给con

2017-06-04 12:33:16 550

原创 C++ 函数

C++函数不能直接返回数组,但可以将数组作为结构体或对象的组成部分来返回。传递一维数组// 如果需要修改数组void f_modify(double ar[], int n);// 如果不修改数组void f_no_change(const double ar[], int n);在函数中,无法使用sizeof运算符来获取一个数组参数的长度,必须依赖程序员传来的长度。传递二维数组int sum

2017-06-04 12:03:21 218

原创 C++ 动态内存分配

在c语言中可以使用malloc()来进行动态内存的分配,用free()来释放内存。需要包含头文件<stdlib.h>int *arr = (int *) malloc (sizeof(int) * N);free(arr);在C++中有更好的方法,使用new运算符。typeName * pointer_name = new typeName;// 只能使用delete来释放new分配的内存,de

2017-06-04 11:09:53 263

原创 C++ 结构体 共用体和枚举

结构体结构体就不做多的介绍了,只说说他的位字段struct sct{ unsigned int sn : 4; // 该字段占用4位 unsigned int : 4; bool goodIn : 1; bool goodTo : 1;};共用体共用体是一中数据格式,他能够存储不同的数据类型,但只能同时存储其中的一种类型。#include <iostream>u

2017-06-04 10:52:03 412

原创 cin详解

cin与hex、oct、dec控制符一起使用,按进制输入#include <iostream>using namespace std;int main(){ int temp; // 按16进制输入 // 输入12 cin >> hex; cin >> temp; // 按16进制输出 // cout << hex; // 输出18

2017-06-01 16:19:45 693

原创 Java DecimalFormat

是NumberFormat 类的子类,主要的作用是用来格式化数字使用,当然,在格式化数字的时候要比直接使用NumberFormat 更加方便,因为可以直接指定按用户自定义方式进行格式化操作,与之前讲的SimpleDateFormat类似,如果要想进行自定义格式化操作,则必须指定格式化操作的模板。 下面给出如何定义模板: 一些例子:import java.text.DecimalFormat;i

2017-05-22 15:23:28 251

转载 Java Calendar和SimpleDateFormat的使用

Java Calendar 类时间操作,这也许是创建和管理日历最简单的一个方案,示范代码很简单。 演示了获取时间,日期时间的累加和累减,以及比较。注意事项:Calendar 的 month 从 0 开始,也就是全年 12 个月由 0 ~ 11 进行表示。Calendar.DAY_OF_WEEK 定义和值如下: Calendar.SUNDAY = 1 Calendar.MONDAY = 2

2017-05-19 21:51:30 324

原创 C++ Map的简单使用

头文件#include <map>申明map<key, value> mymap;插入向map中插入提供了三个重载版本iterator insert( iterator pos, const pair<KEY_TYPE,VALUE_TYPE> &val );// 插入val到pos的后面,然后返回一个指向这个元素的迭代器。void insert( input_iterator start, in

2017-05-19 09:53:28 336

原创 蓝桥杯 带分数

有一点需要注意的是,分子的长度一定不会小于分母,不然就不能够整除了,有了这个剪枝,搜索的次数就少了很多。

2017-05-11 16:53:00 379

原创 蓝桥杯 小朋友排队

只需求出原始数组中,每个元素前比它大的数的个数和每个元素后比它小的数的个数即可。

2017-05-11 13:51:13 362

原创 树状数组

在写程序时突然发现别人有用到树形数组这样一个数据结构,目前具体应用场景不详,只知道可以很快的求出一个数组中下标i到下标j的和。

2017-05-11 10:55:07 263

原创 逆序数

对一个无序序列进行排序,要求一次只能交换相邻的两个数,那么最少需要交换多少次才可以完成排序呢?本问题假设序列所有数各不相同。

2017-05-10 20:48:32 3633 1

空空如也

空空如也

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

TA关注的人

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