H面试(24):调整数组顺序使奇数位于偶数前面

虹软24届校招正式批---测试&测开类笔试预计本周进行 出售2023年数字ic前端设计/FPGA笔记资料,面经,必看book推荐,大厂笔试题整理,常考手撕代码整理,学习路线,大厂笔试面试常考知识点,免费课程推荐等资料。OK,八股几乎都答出。来攒个人品1. 项目中的难点,最初面试官觉得不是很难,详细讲解项目的背景和现有的处理方案的区别2. kv存储结构存在的问题3. hbase结构和hbase结构存。超参数一面题没撕出来(给一堆点判断一共有多少个菱形)用友二面说我的方向不太匹配(投的测开)多乐游戏感觉面的还不错的,啥啥都答上来了,反手一个挂核心原因是我太菜了。 阅读详情

题目:输入一个数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数

位于数组的后半部分,要求时间复杂度为O(n).


#include <assert.h>  
#include <stdio.h> 

void swap (int * a , int *b)  //交换两个数字
{
     int temp;
	 temp = *a;
	 *a = *b;
	 *b = temp;
}
void push_odd_before_even(int * a ,int n)
{   
	assert(a);
	int * begin = &a[0];  //指向数组首元素
    int * end = &a[n-1];  //指向数组末尾元素

	for (int i = 0; i < n; i++ )
	{
		if((*begin & 1)&&(begin!=end)) //是奇数就移到下一位,直接跳到下一循环
		{  
		   begin++;
		   continue;   
		}
		else  //是偶数就放到最后去
		{
		   swap(begin, end);
              *end--;	
		}

	}	
}
int main( )
{
	int a[ ] = {1,5,3,9};
	int n = sizeof(a)/sizeof(int);
    push_odd_before_even(a,n);
	for (int i=0; i<n; i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}





华为手撕代码+剑指offer总结 (python+c语言) 文章目录1.华为手撕代码总结1.1排序问题1.2链表求和1.3树的前中后序遍历(递归/循环写法)1.4树的链表化1.5给一个初始饮料瓶数,三个空瓶换一瓶,可以赊一瓶,求最后能喝几瓶1.6岛屿最大面积问题1.7自己面试手撕的5道算法题2.剑指offer2.1 二维数组查找中的查找2.2 替换空格2.3 从尾到头打印链表2.4 重建二叉树2.5用两个栈实现队列2.6旋转数组的最小数2.7斐波那契数列 ... 阅读详情

相关推荐

面试经历(华为,瑞晟,大华,海康,虹软,顺丰)

经历了一个月左右的奔波,找工作即将落下帷幕。找工作过程中,有很多的感想和苦涩。 感触最深的就是,要笔试或者面试一家公司了,很是希望在网上找到笔经或者面经,给自己的笔试和面试作个参考。 一路下来,有的公司参考经验很多,有的公司却寥寥无几。不管多少,参考资料对于我们来说,都意义非凡,有的真的给了很大的帮助。 此时,我也即将落下找工作的帷幕,就想着把我找工作过程中的笔试面试作个简单的小结(没有百度

sxy102829的专栏 3万+

【剑指offer】面试题14、调整数组顺序使奇数位于偶数前面

题目:输入一个整数数组,实现一个函数来解决该数组中数字的位置,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。 本题思路较为简单,我们只需维护两个指针:第一个指针pHead 初始化为数组的第一个元素,第二个指针pTail 初始化为数组的最后一个元素。根据题目要求:所有奇数位于数组的前半部分,偶数位于数组的后半部分;我们只需: 1、使指针pHead 向后遍历,直到指向的整数为...

weixin_30551963的博客 73

牛客周赛 Round 11 解题报告 | 珂学家 | 线性dp+大剪枝

评测系统依托史,写是都能写出来了,看到通过的就2个,有点恶心昂不算题解的题解:A. 裸的dfs,略B. 从正面做很麻烦,反着来很方便,反正每次操作的元素是确定的。/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param array int整型一维数组 * @ret。/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @return。

2301_79125431的博客 399

Seeker的奇妙求职历险(网易有道二面)

前言 8月24日早上10点,我进行了网易有道的二面。 之前看牛客上很多人都是一面完直接二面,而我等了大概有4天,所以我想可能是大神优先二面,然后挂了之后再让下面一批陪跑吧。 这次面试前面十几分钟就聊了聊项目,然后问我怎么优化的,做了哪些工作,之后就说做题目吧,然后给我出了三道算法题。 第一题还算比较简单,第二题的话没能在面试的时候想明白,第三题应该算是一道场景题。 走格子 给出m*n的方格,计算从左上角走到右下角有几种路径。 经典的走格子问题,写完之后问我能不能优化一下,我说那我考虑采用滚动数组的方式,从后

qq_33241802的博客 647

【博弈论】势博弈(potential game)、EPG以及最佳响应、Nash均衡和帕累托(pareto)最优的理解

文章目录前言一、Potential game二、Nash均衡和Pareto-optimal(帕累托最优)1.Nash 均衡2.Pareto最优三、Best response(最佳响应)四、Exact potential game(EPG)1.合作-傀儡博弈2.合作博弈3.傀儡博弈4.自激博弈5.双边对称交互博弈使用理解 前言 本文主要详细讲解potential game的概念以及Exact potential game 的定义和分类,以及这么博弈方法是如何在论文中引入并使用的,本文仅是对自己在该模块

weixin_44535200的博客 2万+

中国30米分辨率城市建成区数据集 (1972-2023年)

全国城市建成区空间分布数据(1972-2023年),利用Google Earth Engine平台,基于Landsat系列遥感影像提取了1972–2023年城市不透水面,后经过不透水面聚集密度计算方法计算了不透水面聚集密度,通过阈值划分提取了城市建成区,并设置了建成区面积阈值,去除了噪点,获取了全国城市建成区空间分布数据集。该提取能准确刻画城市形态,提取精度高,保持了建成区的完整性。数据集包括41期数据,1972年,1978年,1985-2023年逐年,分辨率为30米,有栅格和矢量两种格式。

地球资源数据云的官方博客 5825

最新【数据结构与算法】【24考研】(三(2),面试字节跳动两轮后被完虐

分析:咱们是将偶数移动到奇数之前,也就是说,要把前面的奇数移动到后面,后面的偶数移动的前面,这个时候我就想到了快速排序,快速排序是大小,咱们这里改成奇偶,也就是说咱们要在前部分虚招一个奇数,后半部分找一个偶数,两者交换,当一次遍历完成所有偶数就到奇数前面了。自己创作代码如下代码分析:分了四种情况前奇数后偶数 交换前偶数后偶数 前继续寻找奇数前奇数后奇数 后继续寻找偶数前偶数后奇数 前后继续寻找标准答案。

2301_76379606的博客 726

DSSP 工具:蛋白质二级结构信息计算与批量处理教程

DSSP(Dictionary of Secondary Structure in Proteins)是一款经典的蛋白质二级结构计算工具,由荷兰癌症研究所(NKI Research)Perrakis 团队维护。它通过分析蛋白质的 PDB 结构文件,能够自动标注每个氨基酸残基的二级结构类型、相对溶剂可及性(暴露面积)等关键信息,为后续的拓扑图绘制、疏水 / 亲水表面分析、二级结构预测模型训练等提供核心数据支持。

good_rrrrr的博客 1839

Array

1、二维数组中的查找 题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 Solution 1: public boolean Find(int target, int [][] array) { int rows=arr...

u012750779的博客 580

如何将rvt(BIM)转换为点云格式

1、为什么将BIM转换为点云格式? 如何使设计BIM与真实场景进行配准,分析在建、未建、已建构建的情况,真实场景是通过点云生产的,和点云配准需要相同的格式。 2、如何转换? 实用工具revit,转换过程如下图,这样就可以转换成三角网格形式。 3、FBX还需要进行一次转换,即转换成点云常用的类型,如bin\ply\pcd等格式。 需要软件cloudcompare.exe,软件下载地址百度云 链接:https://pan.baidu.com/s/1pflcKNc04loBnS1yKR39hw 提取码:obaf

self_Name_的博客 4491

AutoSAR配置与实践(基础篇)2.5 RTE对数据一致性的管理

SWC内部不同的Runnable访问共同全局变量,Runnable类似C文件中的函数,这些函数如果被放在不同Task上运行, 可能出现出现同一时刻多个函数共同运行的情况。可以通过为受影响的任务分配相同的优先级,为受影响的任务分配相同的内部操作系统资源,或者将OS的任务配置为非抢占性来实现。数据一致性:当多个操作同时读写同一个数据,由于任务的抢占,出现了数据被篡改的情况,造成非预期的数据结果。SWC内部变量保护,限定局变量的作用域在变量的作用域在SWC的不同runnable间。

nihaoljq2010的博客 2628

【剑指Offer学习】【所有面试题汇总】

剑指Offer学习   剑指Offer这本书已经学习完了,从中也学习到了不少的东西,现在做一个总的目录,供自已和大家一起参考,学如逆水行舟,不进则退。只有不断地学习才能跟上时候,跟得上技术的潮流! 所有代码下载【https://github.com/Wang-Jun-Chao/coding-interviews】 目录 第01-10题 【剑指Offer学...

asdfrt8686的博客 177

测试用例设计工具大盘点:总有一款适合你

本文旨在帮助测试工程师、开发人员及团队管理者快速了解主流测试用例设计工具的特点、适用场景和选择逻辑。覆盖工具类型包括传统文档工具、开源管理工具、商业集成平台及新兴AI工具,范围涵盖中小团队到大型企业的不同需求。本文从“测试用例设计的痛点”切入,用生活案例解释核心概念;接着按“工具类型”分类盘点主流工具(附优缺点对比表);再通过“小团队/中大型团队/敏捷团队”等真实场景教你选工具;最后展望AI等未来趋势,帮你“一次学透,终身受用”。

项目管理的博客 1592

剑指offer第二版(Python3)--面试题20:表示数值的字符串

请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。

鲁班七号 291

搭建AutoSAR开发环境

任何开发都需要一套开发环境,包括软硬件环境,笔者后续将介绍的是 NXP 的 S32K144 配套的开发板。接下来详细介绍怎么获取这些软硬件工具。仅供个人学习使用!

cfl927096306的博客 6113

语音信号的AGC自适应增益调整matlab仿真

语音信号的自动增益控制(Automatic Gain Control,AGC)是音频处理领域中的一项重要技术。其核心功能是实时调整输入信号的幅度,使其保持在一定范围内,以优化输出信号的质量。AGC广泛应用于语音通信、语音识别、音频录制和播放等领域,旨在解决输入信号幅度波动问题,确保输出信号的稳定性和清晰度。一、AGC的基本原理1.1 幅度调整自动增益控制的基本原理是根据输入信号的幅度动态地调整系统的增益。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 925

剑指offer题解 带讲解 python版 第一部分

目录1、二维数组查找2、替换空格3、从尾到头打印链表3、重建二叉树4、两个栈实现队列5、旋转数组最小数字6.斐波那契数列7、跳台阶8 变态跳台阶9、矩形覆盖10、二进制中1的个数11、整数次方13、o(1)时间内删除链表节点14、调整数组奇数位于偶数前面,并保证相对位置15、链表倒数第k个节点16、链表反转17、合并两个有序链表18、树的子结构19、求二叉树的镜像20、螺旋打印矩阵21、包含min...

weixin_43167121的博客 1637

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

最新【数据结构与算法】【24考研】(2),面试字节跳动的大数据开发工程师该怎么准备

for(j = i;

2401_84592187的博客 656

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

面试刷题10-22

一面视频,面试管真的搞心态。没有我的简历。瞎问 自我介绍。。。。。 spring cloud 微服务没怎么了解过。。。。。 spring boot的一些特性 随便说了一些自动配置 和注解相关的。 问了mysql的索引 order by的字段走索引的条件。必须where 里面存在。 还有sql的优化策略。 jdk8的特性 说了Lambda和stream stream的...

wwxy1995的博客 625
上一篇: H面试(21):在一个升序数组找两数之和
下一篇: H面试程序(5):两个大数相乘
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值