Cracking the coding interview--Q1.7

音频链路分析 音频链路分析摘要 本文分析了蓝牙音频设备(BES2700)的音频传输链路,主要包括通话和音乐播放两种场景: 通话链路: 下行:蓝牙接收数据→解码→通过Codec输出到扬声器 上行:麦克风采集→Codec处理→蓝牙编码发送 音乐播放链路: 通过A2DP协议接收高质量音频数据 经过解码、EQ调节等音频处理后输出 系统采用多线程消息机制处理音频任务,通过mailbox传递控制消息,由回调函数处理具体音频数据流。不同应用场景使用不同的蓝牙协议栈(HFP/HSP用于通话,A2DP用于媒体)和编码方式(mSBC/SBC 阅读详情


原文:

Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.

译文:

写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.


package chapter_1_arraysandstring;

import java.util.Scanner;

/**
 * 写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.
 * 
 * @author LiangGe
 * 
 */
public class Question_1_7 {
	
	/**
	 * 通过建立两个boolean数组分别记录行和列是否出现0
	 * 之后再遍历二维数组,如果当前所在行或者列出现0,就修改为0
	 * 
	 * 时间复杂度 0(n2)
	 */
	public static void changeMatrix(int array[][], int m, int n) {
		boolean rowTag[] = new boolean[m];
		boolean columnTag[] = new boolean[n];
		
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				if(array[i][j] == 0) {
					rowTag[i] = true;
					columnTag[j] = true;
				}
			}
		}
		// 题目没有指明是否是稀疏矩阵,就不确定0出现的次数多不多
		// 如果是稀疏矩阵可以只遍历行或者列,再如果行存在为0就再遍历修改对应行
		// 如果0出现次数多,会导致重复修改
/*		for(int i=0; i<m; i++) {
			if(rowTag[i]) {
				for(int j=0; j<n; j++) {
					array[i][j] = 0;
				}
			}
		}
		
		for(int j=0; j<n; j++) {
			if(columnTag[j]) {
				for(int i=0; i<n; i++) {
					array[i][j] = 0;
				}
			}
		}*/
		
		// 如果0出现的次数比较多,则可以直接遍历二维数组
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				if(rowTag[i] || columnTag[j]) {
					array[i][j] = 0;
				}
			}
		}
	}
	
	public static void printMatrix(int array[][], int m, int n) {
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				System.out.format("%3d", array[i][j]);
			}
			System.out.println();
		}
	}
	
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int m, n;
		// 输入 0 0结束
		while (scanner.hasNext()) {
			m = scanner.nextInt(); 
			n = scanner.nextInt();
			if(m==0 && n==0) {
				break;
			}
			scanner.nextLine();
			int array[][] = new int[m][n];
			
			for(int i=0; i<m; i++) {
				for(int j=0; j<n; j++) {
					array[i][j] = scanner.nextInt();
				}
				scanner.nextLine();
			}
			
			changeMatrix(array, m, n);
			
			printMatrix(array, m, n);
		}
	}
}


2021年全网最细 VirtualBox 虚拟机安装 Ubuntu 20.04.2.0 LTS及Ubuntu的相关配置 目录一、VirtualBox 虚拟机的安装1. VirtualBox 的下载和安装2. 设置 VirtualBox 存储文件夹3. 在 VirtualBox 创建虚拟机二、Linux 操作系统(Ubuntu)的安装1. Linux 操作系统(Ubuntu)的下载2. 安装 Ubuntu3. 启动 Ubuntu三、配置 Ubuntu1. 设置终端2. 设置共享剪贴板3. 设置共享文件夹 一、VirtualBox 虚拟机的安装 VirtualBox 是由德国 Innotek 公司开发,由 Sun Microsy 阅读详情

相关推荐

Unity中URP下的菲涅尔效果实现(个性化修改)

在上篇文章中,我们实现了 URP 下的菲涅尔基础效果,我们在这篇文章中,对其进行自定义化修改。

楠溪泽岸的博客 2063

Cracking the Coding Interview Q1.7

Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 见leetcode Set Matrix Zeroes 转载于:https://www.cnblogs.com/jdflyfly/p/3830587.html

weixin_30699463的博客 91

【TCAX相关】Python 官方手册下载页面(中文+英文)

Python 官方手册下载页面(中文+英文) 中文: https://docs.python.org/zh-cn/3.8/archives/ https://docs.python.org/zh-cn/3.6/archives/ 英文: https://www.python.org/doc/versions/ https://docs.python.org/3/archives/ https://www.python.org/ftp/python/doc/ ...

Seekladoom的博客 1010

【Cracking the coding interview】Q1.7(矩阵置0)

Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0. #include #include #include using namespa

pipi666661的专栏 807

Saturn PCB Toolkit V8.02 实战:5分钟完成10A电源路径的走线与过孔通流验证

本文详细介绍了如何使用Saturn PCB Toolkit V8.02快速验证10A电源路径的走线与过孔通流能力。通过实战案例和参数配置指南,帮助工程师解决大电流PCB设计中的温升失控、过孔瓶颈等核心挑战,提升设计效率和可靠性。

weixin_34194829的博客 447

ROS与UR10e机械臂实战:从零搭建到精准控制

本文详细介绍了如何从零开始搭建ROS与UR10e机械臂的开发环境,包括硬件准备、软件配置、网络设置以及MoveIt!运动控制实战。通过具体的代码示例和常见问题排查,帮助开发者快速掌握UR10e机械臂的精准控制技术,适用于工业自动化和实验室研究场景。

m3n5b7v8c9x的博客 772

Cracking the coding interview--Q10.1~Q10.7

题目10.1 译文: 你有一个篮球架,可以在以下游戏中选择一个来玩。 游戏1:投一次球,进了算赢。 游戏2:投三次球,至少要进2个才算赢。 如果命中率是p,那么p是什么值时你会选游戏1来玩?或p是什么值时你会选择游戏2? 解答10.1 由题意,游戏1的命中率为p;游戏2命中率为:C(2,3)*p^2*(1-p)+p^3=3*p^2-2*p^3,所以由

cfanr 1739

海康摄像头V3.4 升级改造VUE3

摘要:本文介绍了一个基于Vue3的海康威视摄像头组件封装方案。针对官方仅提供HTML版本SDK的问题,作者通过封装实现了Vue3组件化集成,解决了iframe/webview引入方式的弊端。组件核心功能包括实时预览、本地录像、录像下载、截图抓拍等,并优化了SDK初始化逻辑(单例模式)、定位问题修复和错误处理机制。关键技术点包括:1)SDK插件容器定位修复;2)录像下载进度监控;3)多格式图片数据处理;4)多窗口场景下的SDK实例管理。该组件可直接通过npm安装使用,提供了完善的API和事件接口,显著提升了海

LINLINLINShi的博客 113

Cracking the coding interview--Q4

Chapter 4 | Trees and Graphs 4.1 Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ

763

文石NoteX3国行版安装 Google Play经验分享

文石NoteX3国行版安装 Google Play经验分享。

2301_80693261的博客 7592

借助Gemini 3 Pro高效解决课题申报中的五大核心痛点,亲测有效经验分享

之前给大家分享过关于AI辅助课题申报的相关的内容,涵盖了申报书部分撰写技巧,但没针对性拆解各位同仁在实际申报时遇到的卡壳的地方。比如选题范围拿捏不准,定的太大,根本没法落地完成;定的太小,研究价值则体现不了;写综述时,容易单纯罗列文献,缺乏批判性视角,没办法自然融入自己的判断,找不到研究缺口;研究方法部分,可能担心方法设计不够严谨,别人难以复现.....针对这些申报中的高频痛点,接下来七哥会从五个核心要点出发,借助Gemini 3 Pro高效解决这些痛点。

智能AI让学术科研更容易 700

cracking-the-coding-interview的核心秘密:如何用单元测试“定义”面试题?C++ Catch+Python unittest的TDD完整教程

cracking-the-coding-interview 是一个为《Cracking the Coding Interview》(CTCI)第 6 版提供 **C++ 与 Python 双语言解法** 的开源项目,其最大特色是:**每一道面试题的解法都配有完整的自动化单元测试**(C++ 端用 Catch 框架,Python 端用 unittest 框架),自动化测试覆盖率超过 90%。更妙的是

gitblog_00501的博客 317

搭建 Newman + Postman + Git + Jenkins 环境教程

一步步搭建 Newman、Postman、Git 和 Jenkins 的环境。这些工具常用来做 API 测试和 CI/CD 自动化,尤其是 Postman 和 Newman 搭配 Git 和 Jenkins,能实现 API 集合的版本管理和自动测试。

Criss@陈磊 434

Cracking the Coding Interview Chap1 Q1.1

Q1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? Sol.1 : check every char of the string to every other char of

biubiu的专栏 965

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Cracking the coding interview--Q9

Chapter 9 | Sorting and Searching 9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. 插入排序,需要调整数

1020

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Cracking the coding interview--Q9.7

原文: A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the pers

执子之手 547

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Cracking the coding interview--Q1.1

作者:ustcweijie 参考:http://hawstein.com/posts/1.1.html 1. 题目 原文:Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?

蔚蓝天空 546

渣基础:比照Hawstein学Cracking the coding interview(1)

《C++ Primer 第五版》书实在是太长,太厚了。总是看了十几页就看累了,坚持不了多久,想了想还是别勉强自己,jued

低端玩家的记录地 949

Cracking the coding interview Q1.1

最近在看Cracking the coding interview 有一个c++习题版本的,地址地址如下:地址 本人一边看一边尝试着用python写一下 python新手,先练练手

djh512的专栏 1087

Cracking the coding interview--Q17

Chapter 17 | Networking 17.1 Explain what happens, step by step, after you type a URL into a browser. Use as much detail as possible.  先进行DNS的namequery,得到对方的cname或者a记录(当然也可能是IPV6),反正就最后得到对方的IP

630

Cracking the coding interview--Q4.7

题目 原文: You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1. 译文: 有两个非常大的二叉树:T1,有上百万个结点,T2,有上百个

cfanr 1452

Cracking the coding interview--Q4.1

题目 原文: Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root

cfanr 1762
上一篇: Cracking the coding interview--Q1.6
下一篇: Cracking the coding interview--Q1.8
java_wliang
博客等级 码龄15年 19粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值