上一页 1 2 3 4 5 6 7 ··· 15 下一页
摘要: http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/k largest(or smallest) elements in an arrayMarch 1, 2010Question:Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.For example, if given array is [1, 23, 12, 9, 30, 2, 5 阅读全文
posted @ 2013-06-14 21:56 Alan Yang 阅读(340) 评论(0) 推荐(0) 编辑
摘要: http://blog.csdn.net/whinah/article/details/6419680从理论上讲,只要允许使用栈,所有的递归程序都可以转化成迭代。但是并非所有递归都必须用栈,不用堆栈也可以转化成迭代的,大致有两类尾递归:可以通过简单的变换,让递归作为最后一条语句,并且仅此一个递归调用。// recursiveint fac1(int n) { if (n <= 0) return 1; return n * fac1(n-1);}// iterativeint fac2(int n) { int i = 0, y = 1; for (; i <= n; ... 阅读全文
posted @ 2013-06-13 17:08 Alan Yang 阅读(915) 评论(0) 推荐(1) 编辑
摘要: A child is running up a staircase with N steps, and can hop either 1 step,2steps,3 steps at a time. Count how many possible ways the child can run up the stairs. class Upstaircase { static void Main(string[] args) { /* Enter your code here. Read input from STDIN. Print ou... 阅读全文
posted @ 2013-06-13 00:54 Alan Yang 阅读(357) 评论(0) 推荐(0) 编辑
摘要: http://www.geeksforgeeks.org/find-whether-an-array-is-subset-of-another-array-set-1/Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order.Examples:Input: arr1[] = {11, 1, 13, 21, 3, 7}, arr2[] = {11, 3, 7, 1}Output: 阅读全文
posted @ 2013-06-09 16:34 Alan Yang 阅读(309) 评论(0) 推荐(0) 编辑
摘要: http://stackoverflow.com/questions/6349125/are-c-sharp-delegates-thread-safeRegarding the invocation of the delegate the answer is yes.Invoking a delegate is thread-safe because delegates are immutable. However, you must make sure that a delegate exists first. This check may require some synchroniza 阅读全文
posted @ 2013-06-07 17:25 Alan Yang 阅读(266) 评论(0) 推荐(0) 编辑
摘要: http://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation.So 阅读全文
posted @ 2013-06-07 16:40 Alan Yang 阅读(473) 评论(0) 推荐(0) 编辑
摘要: heatoi()function takes a string (which represents an integer) as an argument and returns its value.Following is a simple implementation. We initialize result as 0. We start from the first character and update result for every character.// A simple C++ program for implementation of atoi#include <s 阅读全文
posted @ 2013-06-07 14:38 Alan Yang 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 1st Solution:When I first see this problem, my first thought was in-order traversal. Couldn’t we modify the nodes’ left and right pointers as we do an in-order traversal of the tree? However, we have to beware not to modify the pointers and accessing it at a later time.As we traverse the tree in-ord 阅读全文
posted @ 2013-05-29 16:18 Alan Yang 阅读(512) 评论(1) 推荐(0) 编辑
摘要: From: http://www.skorks.com/2009/09/become-a-better-developer-by-indexing-your-brain/ By Alan SkorkinThis is the fourth post in the teaching and learning series. The teaching and learning series includes the following posts:All Developers Should Know How They Learn BestThe Secret Of Being A Great M. 阅读全文
posted @ 2013-05-27 18:37 Alan Yang 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST./*** Definition for binary tree* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/public class Solution {public TreeNode sortedArrayToBST(int[] num) {/ 阅读全文
posted @ 2013-05-21 17:52 Alan Yang 阅读(298) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 15 下一页