摘要: Problem: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For exa 阅读全文
posted @ 2016-05-27 23:49 liu_ty10 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Problem: Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each 阅读全文
posted @ 2016-05-26 00:45 liu_ty10 阅读(161) 评论(1) 推荐(0) 编辑
摘要: Problem: Invert a binary tree. to One Possible Solution: 阅读全文
posted @ 2016-05-25 18:50 liu_ty10 阅读(92) 评论(0) 推荐(0) 编辑
摘要: Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the f 阅读全文
posted @ 2016-05-23 19:44 liu_ty10 阅读(81) 评论(0) 推荐(0) 编辑
摘要: Problem: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process 阅读全文
posted @ 2016-05-22 20:56 liu_ty10 阅读(103) 评论(0) 推荐(0) 编辑
摘要: Problem: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 阅读全文
posted @ 2016-05-22 01:01 liu_ty10 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Problem: Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". One possible Solut 阅读全文
posted @ 2016-05-21 00:39 liu_ty10 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 1、http://wenku.baidu.com/view/ba2bb84acf84b9d528ea7a31.html?re=view 阅读全文
posted @ 2015-05-15 15:37 liu_ty10 阅读(461) 评论(0) 推荐(0) 编辑
摘要: 贪心的思想:通过每一步都找最优解决问题。因为每一步最优,最后是最优的概率很大。部分背包的思想就是:把最值钱的往包里装,装得越多越好。可见设计算法的人好贪啊,嘿嘿~样例:n种东西,重量是Mi,价值是Vi,单价就是两者之比Pi。C为小包包的容量。最后算出的结果是对应取Xi放到包中。代码如下:#inclu... 阅读全文
posted @ 2014-10-22 17:01 liu_ty10 阅读(346) 评论(0) 推荐(0) 编辑
摘要: 用长分别为100、200、300、400、500、600、700、800、900、1000的10个数组的排列来统计这两种算法的时间复杂性;快速排序程序:#includeusing namespace std;int circle;static int num[11]={0,0,0,0,0,0,0,0... 阅读全文
posted @ 2014-10-19 22:47 liu_ty10 阅读(397) 评论(0) 推荐(0) 编辑