- 博客(30)
- 收藏
- 关注
原创 一个int数组,求乘起来最大的连续子序列
一道题目,和朋友分析了半天,只有以下的一些结论:1. 如果是正数的话,就全部乘起来就可以了2. 如果是偶数个的负数的话,就直接全部乘起来就可以了。3. 单数个负数的话是挺复杂的。。。
2011-05-21 13:32:00 686
原创 给一个数组,求a[i]<a[j]的情况下,j-i的最大值是多少,要求用O(n)时间复杂度
<br />碰到一道,看似挺简单,但是又挺难,到现在还没想出来,先放在这里。<br />
2011-05-21 13:28:00 1459 1
原创 树的深度优先非递归算法
前序遍历(pre-order traverse) public void DFS_Pre(Node root) { Stack s = new Stack(); while (s.Count != 0) { Console.WriteLine(s.Pop().value); if (root.left != null) s.Push(root.l
2011-05-19 12:29:00 815
原创 判断树的两个节点的公共ancestor
<br /> public Node GetCommonAncester(Node root, Node p, Node q) { if (covers(root.left, p) && covers(root.left, q)) root = GetCommonAncester(root.left, p, q); else if (covers(root.right, p) && covers(root
2011-05-19 11:56:00 731
原创 判断两棵二叉树是否是balanced
<br />static void Main(string[] args) { Node root = new Node(); Node c1 = new Node(); Node c2 = new Node(); root.left = c1; root.right = c2; Node c11 = new Node();
2011-05-19 11:39:00 487
原创 螺旋形打印矩阵
<br /><br />代码是从网上copy来的,但是自己理解了一下,并且重新修改了一下,本来他是逆时针打印的,现在我改成顺时针打印,挺好理解的。<br />这里用到的就是int[,]而不是int[][],据说int[,]只有在c#里面有,到现在还不知道具体怎么区分这两个之间的区别。<br /> <br /> int[,] array = new int[6, 6]{<br /> {11,12,13,14,15, 16},<br /> {21,22,23,
2011-05-19 07:12:00 759
原创 再读Dynamic Programming
<br />真后悔大学没有好好学,当时记得老师说过动态规划的题目,但是自己当时根本不知道学这个是干嘛用的。。。<br />现在想起来应该先出来工作两年,面试两年,然后再开始上课就知道这些东西的重要性了!<br />言归正传,来说DP<br /> <br />背包问题是NP完全问题,DP用来求背包问题是最优的可解方案之一。<br />所谓背包问题就是:设有n件物品,每件价值记为Pi,每件体积记为Vi,用一个最大容积为Vmax的背包,求装入物品的最大价值。<br />用一个数组f[i,j]表示取i件商品填充一个
2011-05-19 05:21:00 722
原创 重载运算符
<br />没想到在C#里面也可以重载运算符,还挺有趣的,具体的格式是这样子的:<br />public static decimal operator +(Program a, int b) { return a.i + b; } <br />用的时候也很有趣:<br /> <br />Program p1 = new Program(); Program p2 = new Program();
2011-05-18 16:09:00 423
原创 碰到自己弱项了,决不能放过!
int[][]和int[,]之间的区别。从网上查到int[][]叫二维数组,也算是一个矩阵,矩阵要transform的话也很简单的几句代码。贴一段人家写的代码,感觉还算靠谱,明天自己要写一下!void swap(int &a,int &b) { int temp=a; a=b; b=temp; } void Reverse(int (*a)[3],int n) { int i,j; for(i=0;i > a[i][j]; } R
2011-05-18 15:55:00 532
原创 一道Amazon经典的题目,经常会考到,给一个target数字以及一个数组,求所有的加起来为这个数字的组合
<br />用HashTable来做最方便,其实这道题目已经很久之前就知道了,怎么做已经滚瓜烂熟了,结果我在写code的时候还碰到了这样那样的问题,看来有些问题看似容易,但是没有实践一下的话说不定真到到实践的时候就又会碰到一大堆问题的。<br />以下贴一下这个函数的实现,可能写的比较冗余了,但是算法还是基本能体现的<br />public static void FindTarget2Numbers(int[] a, int targetNumber) { Ha
2011-05-18 13:37:00 1220
原创 What's the difference between overload and override
<br />Overload means same function name defined in the class, but with different parameters. It's just about the polymophysm.<br />void func( int );<br />void func( double );<br />void fund( unsigned int );<br /> <br />Override means same function name wit
2011-05-18 13:06:00 942
原创 What's the difference between Heap and Stack
也算是C++里面的一个概念吧。另外还涉及到了statichttp://www.cnblogs.com/jsean/articles/1599801.html
2011-05-17 15:35:00 692
原创 What's the difference between Dictionary, Hashtable & Hashset?
<br />This is just the reference. Will post the difference late when have time.<br />http://suebuntu.blogspot.com/2010/06/c-dictionary-hashtable-and-hashset.html
2011-05-17 09:01:00 626
原创 Amazon面试题目
<br /><br />1. Computer Fundemental<br />2. OO design<br />3. Coding question<br />4. Data structure<br />5. Algorythm<br />6. Edge case<br />7. Quality Ensurance.<br />8. Customer Focus<br />9.
2011-05-17 07:02:00 1524
原创 How to answer tell me about yourself question.
<br />Non-tech related question.
2011-05-11 02:52:00 470
原创 一道数据库的概念题
<br />Do you know what's the ACID?<br /> <br /> <br />http://en.wikipedia.org/wiki/ACID<br /> <br />atomicity, consistency, isolation, durability is a set of property which garentee the database transaction processed reliable.<br /> <br /> <br />Atomicity
2011-05-10 10:22:00 582
原创 快速排序
<br />今天研究了一下快速排序法,发现自己还真笨,快速排序法到现在都还没搞清楚。<br />这个方法用的是递归(每做一次partition,都会将pivotloc放到中间,既把比它小的放左边,比它大的放右边)<br />public void QuickSort(int [] r, int low, int high) { int pivotloc = 0; if (low < high) {
2011-05-08 16:01:00 475
原创 Write a method to replace all spaces in a string with ‘%20’.
exclusively for XU-bp75mklu3ja@checkout.google.com21.1 Write a method to replace all spaces in a string with ‘%20’. pg 60SOLUTIONSThe algorithm is as follows:1. Count the number of spaces during the first scan of the string.2. Parse the string ag
2011-05-08 02:35:00 1367
原创 查询链表是否有重合节点
<br />和同事讨论了一下,有好几种方法是可行的:<br />1. 算出两个的<br />2. 将链表A走完,末尾指向的B的头节点<br />3. 将A链表倒转,然后走B链表,如果B链表的最后一个节点是A链表之前的头节点,则表示重合。<br />4. 用Hashtable来存储A链表,然后走B链表,来判断hashtable里面是否有重复节点存在。<br />public Node GetFirstDuplicateNode(Node a, Node b) { i
2011-05-07 03:22:00 1123
原创 求出两个字符串的最长公共子串
这道题要用到suffex-tree的概念,可能还需要用到动态规划(英文可能叫Dynamic Programming),现在突然有事情要做,之后一定补上。下面是wiki的解释:http://en.wikipedia.org/wiki/Longest_common_substring_problem
2011-05-06 05:58:00 622
原创 向右swap int数组
public void MoveArray(int[] arr, int n) { int index = 0; int count = 0; int len = arr.Length; n = n % len; int prev = arr[0]; while (count
2011-05-05 14:09:00 409
原创 求出int数组中和最大的子序列
public int GetMaxSum(int[] arr) { int temp = 0; int max1 = 0; int max2 = 0; for (int i = 0; i 0) { max1 = temp; } else
2011-05-05 02:41:00 426
原创 输入一个字符串的anagram的C#算法
<br />输出字符串所有的anagram的string,用的是递归调用的办法。non-recursive: TODO!!!<br /> <br />public void GetAnagramString(string str1, string str2) { if (str1.Length < 1) Console.WriteLine(str2 + str1); else
2011-05-04 09:52:00 997
原创 Some other questions
1. What's the test plan need to contain?2. What's the SDLC?3. If you manager don't agree your estimation. For example, the manday you provide is more than he want.
2011-05-04 04:48:00 449
原创 计算机英语词汇贴
<br />异或:Exclusive or<br />小括号:bracket (Parentheses)<br />中括号:square brackets<br />大括号:brace<br /><br />
2011-05-03 03:24:00 570
原创 不用加号计算加法
<br />int add(int a, int b){ if(b==0) { return a; } if(a==0) { return b; } int sum=a^b; int temp = a&b; int carry = temp<<1; return add(sum, carry);} <br />用异或算出相加出来的各位(因为1和0相加才不会进位,所以用^异或符号,进位则是靠后面),然后用& 算出进位(当此位都为1时才会进位,所以用&
2011-05-03 02:23:00 2020
原创 C++中各种运算符的知识
<br />以下是各种不太常见的运算符,很多平时一般用不到,但是在写算法的时候却会被考到:<br /> <br />&(按位与)、|(按位或)、^(按位异或)、~ (按位取反)。 <br /><br />其中,按位取反运算符是单目运算符,其余均为双目运算符。 <br /><br />位运算符的优先级从高到低,依次为~、&、^、|, <br /> <br /> (1)左移运算符( < <) <br /> 左移运算将一个位串信息向左移指定的位,右端空出的位用0补充。例如014 < <2,结
2011-05-03 02:06:00 912
原创 some non-tech related question
1. Why do you want to join microsoft?2. Why do you want to join our team instead of your team?3. Need to prepare some question about the project you apply.4. If the testing schedule changed just before the deadline. How would you do?5. If some p0 bug found
2011-05-01 14:39:00 590
原创 找出circular的linked list的第一个元素
再简单不过了,但是程序写好了,竟然运行不过去,挺奇怪的,出来的结果不是预料中的。十分让我意外。不知道哪里有问题了。#include using namespace std;typedef struct Node { char data; Node* next;} Node;bool createList(Node **head){ *head = NULL; return true;}void addNode(Node **head, char c){
2011-05-01 03:20:00 518
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人