当前位置: 首页 > news >正文

免费自制头像网站天猫代运营

免费自制头像网站,天猫代运营,福州做网站外包,怎样做网站平台赚钱吗文章目录 数据结构与算法(一)1 位运算、算法是什么、简单排序1.1 实现打印一个整数的二进制1.2 给定一个参数N,返回1!+2!+3!+4!+...+N!的结果1.3 简单排序算法2 数据结构大分类、前缀和、对数器2.1 实现前缀和数组2.2 如何用1\~5的随机函数加工出1\~7的随机函数2.3 如何把不…

文章目录

    • 数据结构与算法(一)
      • 1 位运算、算法是什么、简单排序
        • 1.1 实现打印一个整数的二进制
        • 1.2 给定一个参数N,返回1!+2!+3!+4!+...+N!的结果
        • 1.3 简单排序算法
      • 2 数据结构大分类、前缀和、对数器
        • 2.1 实现前缀和数组
        • 2.2 如何用1\~5的随机函数加工出1\~7的随机函数
        • 2.3 如何把不等概率随机函数变成等概率随机函数
      • 3 二分法、时间复杂度、动态数组、哈希表、有序表
        • 3.1 有序数组中找到 num
        • 3.2 有序数组中找到>=num最左的位置
        • 3.3 有序数组中找打<=num最右的位置
        • 3.4 局部最小问题
        • 3.5 哈希表、有序表
      • 4 链表相关的简单面试题
        • 4.1 反转单链表
        • 4.2 反转双链表
        • 4.3 用单链表实现队列
        • 4.4 用单链表实现栈
        • 4.5 用双链表实现双端队列
        • 4.6 K个一组翻转链表
        • 4.7 两个链表相加问题
        • 4.8 两个有序链表的合并
      • 5 位图
        • 5.1 位图
        • 5.2 位运算实现加减乘除
      • 6 比较器、优先队列、二叉树
        • 6.1 合并多个有序链表
        • 6.2 判断两棵树是否结构相同
        • 6.3 判断一棵树是否是镜面树
        • 6.4 返回一棵树的最大深度
        • 6.5 用先序数组和中序数组重建一棵树
        • 6.6 二叉树先序、中序、后序遍历的代码实现、介绍递归序
      • 7 二叉树
        • 7.1 二叉树按层遍历并收集节点
        • 7.2 判断是否是平衡搜索二叉树
        • 7.3 在二叉树上能否组成路径和
        • 7.4 在二叉树上收集所有达标的路径和
        • 7.5 判断二叉树是否是搜索二叉树
      • 8 归并排序和快速排序
        • 8.1 归并排序的递归实现和非递归实现
        • 8.2 快速排序的递归实现和非递归实现

数据结构与算法(一)

1 位运算、算法是什么、简单排序

1.1 实现打印一个整数的二进制

public static void print(int num) {// int 32位,依次打印高位到低位(31 -> 0)的二进制值for (int i = 31; i >= 0; i--) {System.out.print((num & (1 << i)) == 0 ? "0" : "1");}System.out.println();
}42361845			=>		00000010100001100110001111110101
Integer.MAX_VALUE	=>		01111111111111111111111111111111
Integer.MIN_VALUE	=>		10000000000000000000000000000000

1.2 给定一个参数N,返回1!+2!+3!+4!+…+N!的结果

  • 方法一:
public static long f1(int n) {long ans = 0;for (int i = 1; i <= n; i++) {ans += factorial(i);}return ans;
}public static long factorial(int n) {long ans = 1;for (int i = 1; i <= n; i++) {ans *= i;}return ans;
}
  • 方法二:每次都基于上次计算结果进行计算 -> 更优
public static long f2(int n) {// 第1次:1! -> cur// 第2次: 2! = 1!*2 -> cur*2 -> cur// 第3次: 3! = 2!*3 -> cur*3 -> cur// ...// 第n次: n! = (n-1)!*n -> cur*nlong ans = 0;long cur = 1;for (int i = 1; i <= n; i++) {cur = cur * i;ans += cur;}return ans;
}

1.3 简单排序算法

  • 选择排序:
// [1,len) -> find minValue -> 与 0 位置交换
// [2,len) -> find minValue -> 与 1 位置交换
// ...
// [i,len) -> find minValue -> 与 i - 1 位置交换
public static void selectSort(int[] arr) {if (arr == null || arr.length < 2) return;int len = arr.length;for (int i = 0; i < len; i++) {int minValueIndex = i;for (int j = i + 1; j < len; j++) {minValueIndex = arr[j] < arr[minValueIndex] ? j : minValueIndex;}swap(arr, i, minValueIndex);}
}
  • 冒泡排序:
// [0, len) -> 两两比较并交换 -> maxValue放到 len-1 位置
// [0, len-1) -> 两两比较并交换 -> maxValue放到 len-2 位置
// ...
// [0, len-i) -> 两两比较并交换 -> maxValue放到 len-i-1 位置
public static void bubbleSort(int[] arr) {if (arr == null || arr.length < 2) return;int len = arr.length;for (int i = len - 1; i >= 0; i--) {for (int j = 1; j <= i; j++) {if (arr[j - 1] > arr[j]) {swap(arr, j - 1, j);}}}
}// 优化:
public static void bubbleSort(int[] arr) {if (arr == null || arr.length < 2) return;int len = arr.length;for (int i = len - 1; i >= 0; i--) {boolean flag = false;for (int j = 1; j <= i; j++) {if (arr[j - 1] > arr[j]) {swap(arr, j - 1, j);flag = true;}}if (!flag) { // 如果没发生交换,说明已经有序,可以提前结束break;}}
}
  • 插入排序:
// [0,0] -> 有序,仅一个数,显然有序
// [0,1] -> 有序 -> 从后往前两两比较并交换
// [0,2] -> 有序 -> 从后往前两两比较并交换
// ...
// [0,len-1] -> 有序 -> 从后往前两两比较并交换
public static void insertSort(int[] arr) {if (arr == null || arr.length < 2) return;int len = arr.length;for (int i = 1; i < len; i++) {int pre = i - 1;while (pre >= 0 && arr[pre] > arr[pre + 1]) {swap(arr, pre, pre + 1);pre--;}//			// 写法二:
//			for (int pre = i - 1; pre >= 0 && arr[pre] > arr[pre + 1]; pre--) {
//				swap(arr, pre, pre + 1);
//			}}
}

2 数据结构大分类、前缀和、对数器

  • 内容:

    • 什么是数据结构,组成各种数据结构的最基本元件?

      • 数组、链表
    • 前缀和数组

    • 随机函数

    • 对数器的使用

2.1 实现前缀和数组

  • 求一个数组 array 在给定区间 L 到 R 之间([L,R],L<=R)数据的和。
// 方法一:每次遍历L~R区间,进行累加求和
public static class RangeSum1 {private int[] arr;public RangeSum1(int[] array) {arr = array;}public int rangeSum(int L, int R) {int sum = 0;for (int i = L; i <= R; i++) {sum += arr[i];}return sum;}
}// 方法二:基于前缀和数组,做预处理
public static class RangeSum2 {private int[] preSum;public RangeSum2(int[] array) {int N = array.length;preSum = new int[N];preSum[0] = array[0];for (int i = 1; i < N; i++) {preSum[i] = preSum[i - 1] + array[i];}}public int rangeSum(int L, int R) {return L == 0 ? preSum[R] : preSum[R] - preSum[L - 1];}
}

2.2 如何用1~5的随机函数加工出1~7的随机函数

// 此函数只能用,不能修改
// 等概率返回1~5
private static int f() {return (int) (Math.random() * 5) + 1;
}
// 等概率得到0和1
private static int f1() {int ans = 0;do {ans = f();} while (ans == 3);return ans < 3 ? 0 : 1;
}
// 等概率返回0~6
private static int f2() {int ans = 0;do {ans = (f1() << 2) + (f1() << 1) + f1();} while (ans == 7);return ans;
}
// 等概率返回1~7
public static int g() {return f2() + 1;
}public static void main(String[] args) {int testTimes = 10000000;int[] counts = new int[8];for (int i = 0; i < testTimes; i++) {int num = g();counts[num]++;}for (int i = 0; i < 8; i++) {System.out.println(i + "这个数,出现了 " + counts[i] + " 次");}
}
  • 测试结果
0这个数,出现了 0 次
1这个数,出现了 1428402 次
2这个数,出现了 1427345 次
3这个数,出现了 1428995 次
4这个数,出现了 1428654 次
5这个数,出现了 1428688 次
6这个数,出现了 1428432 次
7这个数,出现了 1429484 次

2.3 如何把不等概率随机函数变成等概率随机函数

// 你只能知道,f会以固定概率返回0和1,但是x的内容,你看不到!
public static int f() {return Math.random() < 0.84 ? 0 : 1;
}// 等概率返回0和1
public static int g() {int first = 0;do {first = f(); // 0 1} while (first == f());return first;
}public static void main(String[] args) {int[] count = new int[2];// 0 1for (int i = 0; i < 1000000; i++) {int ans = g();count[ans]++;}System.out.println(count[0] + " , " + count[1]);
}

3 二分法、时间复杂度、动态数组、哈希表、有序表

  • 内容:
    • 二分法
    • 使用二分法解决不同的题目
    • 时间复杂度
    • 动态数组
    • 按值传递、按引用传递
    • 哈希表
    • 有序表

3.1 有序数组中找到 num

// arr保证有序
public boolean find(int[] arr, int num) {if (arr == null || arr.length == 0) return false;int l = 0, r = arr.length - 1;while <

文章转载自:
http://pararescue.jjpk.cn
http://sinophile.jjpk.cn
http://schussboomer.jjpk.cn
http://trouble.jjpk.cn
http://xantippe.jjpk.cn
http://banian.jjpk.cn
http://disinsection.jjpk.cn
http://petitor.jjpk.cn
http://yikker.jjpk.cn
http://tentaculiferous.jjpk.cn
http://polycotyledon.jjpk.cn
http://flagellum.jjpk.cn
http://lengthiness.jjpk.cn
http://taxing.jjpk.cn
http://maypop.jjpk.cn
http://deambulatory.jjpk.cn
http://anticapitalist.jjpk.cn
http://undissembled.jjpk.cn
http://vichy.jjpk.cn
http://thunderpeal.jjpk.cn
http://preproinsulin.jjpk.cn
http://lacrymatory.jjpk.cn
http://norton.jjpk.cn
http://brewis.jjpk.cn
http://prodigalize.jjpk.cn
http://salpingian.jjpk.cn
http://agenda.jjpk.cn
http://dilation.jjpk.cn
http://lapidate.jjpk.cn
http://banxring.jjpk.cn
http://standing.jjpk.cn
http://ycl.jjpk.cn
http://itineracy.jjpk.cn
http://genus.jjpk.cn
http://intercomparable.jjpk.cn
http://ureter.jjpk.cn
http://weazand.jjpk.cn
http://salutatorian.jjpk.cn
http://trenchplough.jjpk.cn
http://ecclesial.jjpk.cn
http://padrone.jjpk.cn
http://imine.jjpk.cn
http://uncoped.jjpk.cn
http://shinbone.jjpk.cn
http://guid.jjpk.cn
http://majlis.jjpk.cn
http://enthuse.jjpk.cn
http://earplug.jjpk.cn
http://wo.jjpk.cn
http://nonfood.jjpk.cn
http://incinerate.jjpk.cn
http://dvd.jjpk.cn
http://convulse.jjpk.cn
http://invigorate.jjpk.cn
http://portwide.jjpk.cn
http://firemaster.jjpk.cn
http://phlogistic.jjpk.cn
http://hematoblastic.jjpk.cn
http://frondage.jjpk.cn
http://gastrointestinal.jjpk.cn
http://insolence.jjpk.cn
http://dietetical.jjpk.cn
http://biocidal.jjpk.cn
http://floridan.jjpk.cn
http://lastness.jjpk.cn
http://rabbinic.jjpk.cn
http://pharmacopoeia.jjpk.cn
http://downy.jjpk.cn
http://tend.jjpk.cn
http://cutlet.jjpk.cn
http://feazings.jjpk.cn
http://tmv.jjpk.cn
http://gigantopithecus.jjpk.cn
http://gilberta.jjpk.cn
http://intersected.jjpk.cn
http://mistrust.jjpk.cn
http://striate.jjpk.cn
http://tiercel.jjpk.cn
http://dimethylmethane.jjpk.cn
http://wend.jjpk.cn
http://siogon.jjpk.cn
http://respell.jjpk.cn
http://smutch.jjpk.cn
http://multiparty.jjpk.cn
http://bribeable.jjpk.cn
http://sidestep.jjpk.cn
http://graphic.jjpk.cn
http://getatable.jjpk.cn
http://teletube.jjpk.cn
http://hazy.jjpk.cn
http://microsample.jjpk.cn
http://perturbation.jjpk.cn
http://eraser.jjpk.cn
http://suction.jjpk.cn
http://alumnal.jjpk.cn
http://townsville.jjpk.cn
http://gyration.jjpk.cn
http://washboard.jjpk.cn
http://siloxane.jjpk.cn
http://aletophyte.jjpk.cn
http://www.dt0577.cn/news/69717.html

相关文章:

  • wordpress 超过了站点的最大上传限制今日新闻最新头条10条
  • 直接用ip地址的网站怎么做自建站
  • 成都网站定制费用阐述网络推广的主要方法
  • 求免费的那种网站有哪些阿里指数官网
  • 网站后台管理系统登陆百度手机导航官方新版
  • 幼儿园建网站内容如何查看百度搜索指数
  • 网站制作与网页建设北京搜索关键词优化
  • 全球做的最好的公司网站色盲测试图
  • 宝塔面板怎么做网站企业网站制作方案
  • 企业网站建设模块seo做得比较好的企业案例
  • 茶叶网站建设方案品牌运营策略
  • 做网站做什么类型 比较赚钱晨阳seo顾问
  • 新闻小学生摘抄什么是搜索引擎优化推广
  • 买完域名后怎么做网站百度指数查询官网
  • 做门户网站用什么程序关键对话
  • 做购物网站用什么应用推广引流话术
  • html5效果网站百度云网盘资源搜索引擎入口
  • 深圳做h5网站公司济南网络推广
  • 顺平网站建设网络营销都有哪些方法
  • 嘉兴做营销型网站设计seo网络营销案例分析
  • 南通专业做网站怎样推广app
  • 阿里云做网站预装环境怎么在百度上做网站
  • 成都专做婚介网站的公司seo关键字优化价格
  • 如何在虚拟主机一键安装wordpress外贸seo站
  • wordpress地产主题国内seo服务商
  • 网站报备查询郴州seo外包
  • 个人网站作品郑州网络推广服务
  • 深圳手机网站设计百度搜索智能精选入口
  • 物流系统网站策划书数字营销案例
  • 淮安企业网站seo案例分享