随笔分类 - 笔试面试
摘要:问题: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 结点的定义如下: /** * Defini...
阅读全文
摘要:问题: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it with...
阅读全文
摘要:问题: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never d...
阅读全文
摘要:问题: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. 依旧还是那个熟悉的味道,如...
阅读全文
摘要:问题: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, bu...
阅读全文
摘要:问题: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the sto...
阅读全文
摘要:问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 Have you thought about this? Here are some good questions to ask before coding. Bonus p...
阅读全文
摘要:问题: Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 分析: ...
阅读全文
摘要:问题: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without us...
阅读全文
摘要:问题: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 分析: 二维数组a[n][n]顺时针旋转90度,要解决这个问题,无疑,第一件事儿就...
阅读全文
摘要:题目:输入两个数(m,n),m表示牛的头数,n表示查询的个数。查询时输入两个数(x,y),表示查询范围的起始值和终止值,查询结果是,这个区间内牛重量的最大值减去牛重量的最小值,数量级为1000,000 设计每次查询的复杂度为logm。例如,输入:6 31734251 54 62 2输出:630分析:...
阅读全文
摘要:题目:二维数组中,每行从左到右递增,每列从上到下递增,设计一个算法,找其中的一个数分析:二维数组这里把它看作一个矩形结构,如图所示:128924912471013681115在做这道题的时候我最先考虑的是每次比较对角线上的元素可能可以取得较好的效果,以查找9为例,从1(0,0)开始,19,这个时候可...
阅读全文