08 2015 档案
摘要:Convert a non-negative integer num to its English words representation. Example 1: Input: num = 123 Output: "One Hundred Twenty Three" Example 2: Inpu
阅读全文
摘要:7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only the add operator.这道题让我们实现乘法加法和除法,而且规定了只能使用加法。那么我们先...
阅读全文
摘要:7.3 Given two lines on a Cartesian plane, determine whether the two lines would intersect.这道题说是在笛卡尔坐标系中,让我们确定两条直线是否相交。那么我们首先要写个直线的类来表示直线,最常见的表示方法为y=kx...
阅读全文
摘要:7.2 There are three ants on different vertices of a triangle. What is the probability of collision (between any two or all of them) if they start walk...
阅读全文
摘要:7.1 You have a basketball hoop and someone says that you can play one of two games.Game 1: You get one shot to make the hoop.Game 2: You get three sho...
阅读全文
摘要:6.6 There are 100 closed lockers in a hallway. A man begins by opening all 100 lockers. Next, he closes every second locker. Then, on his third pass, ...
阅读全文
摘要:6.5 There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. If it's dropped from any floor below, it will not b...
阅读全文
摘要:在LeetCode中的Surrounded Regions 包围区域这道题中,我们发现用DFS方法中的最后一个条件必须是j > 1,如下面的红色字体所示,如果写成j > 0的话无法通过OJ,一直百思不得其解其中的原因,直到有网友告诉我说他验证了最后一个大集合在本地机子上可以通过,那么我也来验证看看吧...
阅读全文
摘要:在Qt项目开发完成后,我们想将项目打包发布成一个可执行文件,需要做如下步骤:首先,将项目中的release文件中的可执行文件拷到一个新建的文件夹中,例如project.exe,用Qt自带的生成必备的dll文件的程序windeployqt,来把必要的动态库拷到该文件夹中,打开命令行,输入 windep...
阅读全文
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1,
阅读全文
摘要:6.4 A bunch of people are living on an island, when a visitor comes with a strange order: all blue-eyed people must leave the island as soon as possib...
阅读全文
摘要:6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four qu...
阅读全文
摘要:6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are given 31 dominos, and a single domino can cover ex...
阅读全文
摘要:6.1 You have 20 bottles of pills. 19 bottles have 1.0 gram pills, but one has pills of weight 1.1 grams. Given a scale that provides an exact measurem...
阅读全文
摘要:5.8 A monochrome screen is stored as a single array of bytes, allowing eight consecutive pixels to be stored in one byte.The screen has width w, where
阅读全文
摘要:在C++中,unsigned char用来表示一个字节,也就是8位大小的值,那么我们如何来打印出其值呢,用cout直接打印会乱码,我们可以通过下面两种方法来打印:cout (screen[i]) << endl;printf("%u\n", screen[i]);
阅读全文
摘要:http://www.pearltrees.com/t/kinect-capture-scanner/id2814260
阅读全文
摘要:5.7 An array A contains all the integers from 0 to n, except for one number which is missing. In this problem, we cannot access an entire integer in A...
阅读全文
摘要:5.6 Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 a...
阅读全文
摘要:Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example: Note: Hint: 这道题是之前那
阅读全文
摘要:Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example
阅读全文
摘要:在Qt程序调试的时候,经常需要打印一些变量,那么我们就需要使用qDebug()函数,这种函数有两种使用方法,如下所示:QString s = "Jack";qDebug() << "My name is " << s << ", nice to meet you!" << endl;qDebug("...
阅读全文
摘要:Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements tha
阅读全文
摘要:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Follow up:Could you do it without any lo
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5"
阅读全文
摘要:OpenCV中的CvArr*的定义的一个空类型的指针,可以转换为其派生类CvMat和IplImage,那么如何将其转化为cv::Mat呢,其实很简单,只需要一行代码即可:// CvArr *_imgcv::Mat img = cv::cvarrToMat(_img);
阅读全文
摘要:在OpenCV中,比较常见的是矩形遮罩CvRect,没有专门提供圆形的mask,那么我们只能自己写一个来模拟圆形mask的函数,需要提供的参数为原图的大小,以及圆形mask的圆心位置和半径即可,返回一个cv::Mat型的mask,参见代码如下:// C APIcv::Mat extractCircu...
阅读全文
摘要:5.5 Write a function to determine the number of bits required to convert integer A to integer B.EXAMPLEInput: 31,14Output: 2 这道题给了我们两个数字A和B,问如果将A转化为B需
阅读全文
摘要:5.4 Explain what the following code does: ((n & (n-1)) == 0).这道题让我们解释一个表达式((n & (n-1)) == 0),是说一个数跟比它小1的数字按位相与,结果全是0的情况,那么说明两个数每个位置上至少都有一个0,那么最有可能的情况是...
阅读全文
摘要:5.3 Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.
阅读全文
摘要:5.2 Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represent...
阅读全文
摘要:5.1 You are given two 32-bit numbers, N and M, and two bit positions, land j. Write a method to insert M into N such that M starts at bit j and ends a...
阅读全文
摘要:Matlab是矩阵运算的神器,所以可以很轻易的交换任意行或列,而且写法非常简洁,如下所示:a = [1 2 3; 4 5 6; 7 8 9];b = a;b(:,[1;2]) = b(:,[2;1]); % Swap col 1 and 2c = a;c([1;2],:) = c([2;1],:);...
阅读全文
摘要:4.9 You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum to a given value. The path does
阅读全文
摘要:在MatLab中,我们有时要给画出的点按一定顺序标上序号,下面这个简单的例子实现这个功能:x=rand(1,10);y=rand(1,10);plot(x,y,'r*');text(x+0.02,y,num2cell(1:10));
阅读全文
摘要:4.8 You have two very large binary trees: Tl, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree...
阅读全文
摘要:4.7 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data struc...
阅读全文
摘要:4.6 Write an algorithm to find the'next'node (i.e., in-order successor) of a given node in a binary search tree. You may assume that each node has a l...
阅读全文
摘要:一、Matlab绘图中用到的直线属性包括:(1)LineStyle:线形(2)LineWidth:线宽(3)Color:颜色(4)MarkerType:标记点的形状(5)MarkerSize:标记点的大小(6)MarkerFaceColor:标记点内部的填充颜色(7)MarkerEdgeColor:...
阅读全文
摘要:我们在使用OpenCV时,有时候需要对现有图片剪裁,比如只需要一个小窗口中的内容,那么我们可以通过OpenCV的兴趣区域 Region of Interest (ROI) 来很轻易的实现,操作也很简单,首先建立一个新的IplImage图片,大小为你需要剪裁出来的大小,然后建立一个该大小的CvRect...
阅读全文
摘要:4.5 Implement a function to check if a binary tree is a binary search tree.LeetCode上的原题,请参见我之前的博客Validate Binary Search Tree 验证二叉搜索树。
阅读全文
摘要:希爾頓:蘇梅島,馬爾地夫,大溪地 Bora Bora ,夏威夷茂宜島。凱悅:馬爾地夫,夏威夷茂宜島,Cancun。洲際:大溪地 Bora Bora,蘇梅島。費爾蒙:Cancun,加拿大,夏威夷茂宜島,百慕達卡爾森:倫敦,巴黎,其他歐洲。
阅读全文
摘要:1.传统方法-搜!所熟知的美国订票三大门户网站: Orbitz, Travelocity & Expedia,以及美国订票超级aggregator: Kayak, Mobissimo, SideStep, FareChase. 然后这不是重点....Booking Buddy强大的搜索小帮手,只用输...
阅读全文
摘要:我们有时候在项目中需要将OpenCV中的cv::Mat导入MatLab进行分析与处理,那么如果把数据转过去呢,我们的做法是首先将cv::Mat导出为txt文件,或者是yml文件,请参见我之前的博客Write cv::Mat to a file。导出的txt文件可以直接load进MatLab,如果数据...
阅读全文
摘要:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = ...
阅读全文
摘要:4.4 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll...
阅读全文