• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页
2015年3月19日
转载:如何在面试中写出好的代码
摘要: 一下都是我面试的经验和教训,欢迎各位大牛指正或者补充 1. 写代码之前,大脑里面要有个whole picture,不能想到哪儿写到哪儿。是你的大脑在写代码,而不是白板上你的手在代码。你的手只是一个printer里面的喷头而已,是它把你大脑里面的代码print到白板上,你的大脑才是控制那个喷头的芯片。 阅读全文
posted @ 2015-03-19 03:55 neverlandly 阅读(1763) 评论(0) 推荐(1)
2015年3月18日
F面经:painting house
摘要: There are a row of houses, each house can be painted with three colors red, blue and green. The cost of painting each house with a certain color is di... 阅读全文
posted @ 2015-03-18 04:49 neverlandly 阅读(1612) 评论(0) 推荐(0)
2015年3月16日
Lintcode: Merge Sorted Array II
摘要: Merge two given sorted integer array A and B into a new sorted integer array.ExampleA=[1,2,3,4]B=[2,4,5,6]return [1,2,2,3,4,4,5,6]ChallengeHow can you... 阅读全文
posted @ 2015-03-16 04:41 neverlandly 阅读(598) 评论(0) 推荐(0)
Lintcode: Median
摘要: Given a unsorted array with integers, find the median of it. A median is the middle number of the array after it is sorted. If there are even numbers ... 阅读全文
posted @ 2015-03-16 03:56 neverlandly 阅读(1749) 评论(0) 推荐(0)
2015年3月15日
Climbing Stairs - Print Path
摘要: stair climbing, print out all of possible solutions of the methods to climb a stars, you are allowed climb one or two steps for each time; what is tim... 阅读全文
posted @ 2015-03-15 11:35 neverlandly 阅读(548) 评论(0) 推荐(0)
2015年3月14日
Lintcode: Maximum Subarray III
摘要: Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguou... 阅读全文
posted @ 2015-03-14 10:53 neverlandly 阅读(465) 评论(0) 推荐(0)
Leetcode: Reverse Bits
摘要: Reverse Integer那道题会考虑溢出,因为那是reverse each digit,这里不会溢出,因为reverse的是each bit Q:如果该方法被大量调用,或者用于处理超大数据(Bulk data)时有什么优化方法?A:这其实才是这道题的精髓,考察的大规模数据时算法最基本的优化方法 阅读全文
posted @ 2015-03-14 07:06 neverlandly 阅读(770) 评论(0) 推荐(0)
Leetcode: Number of 1 Bits
摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit i... 阅读全文
posted @ 2015-03-14 06:02 neverlandly 阅读(474) 评论(0) 推荐(0)
Lintcode: Maximum Subarray II
摘要: Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the ... 阅读全文
posted @ 2015-03-14 05:49 neverlandly 阅读(474) 评论(0) 推荐(0)
Lintcode: Maximum Subarray Difference
摘要: Given an array with integers.Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest.Return the largest difference.NoteThe ... 阅读全文
posted @ 2015-03-14 05:16 neverlandly 阅读(1204) 评论(0) 推荐(0)
2015年3月12日
Lintcode: Majority Number II
摘要: Given an array of integers, the majority number is the number that occurs more than 1/3 of the size of the array.Find it.NoteThere is only one majorit... 阅读全文
posted @ 2015-03-12 06:50 neverlandly 阅读(1234) 评论(0) 推荐(0)
Lintcode: Lowest Common Ancestor
摘要: Given the root and two nodes in a Binary Tree. Find the lowest common ancestor(LCA) of the two nodes.The lowest common ancestor is the node with large... 阅读全文
posted @ 2015-03-12 05:42 neverlandly 阅读(549) 评论(0) 推荐(0)
2015年3月9日
Twitter OA prepare: Two Operations
摘要: 准备T家OA,网上看的面经最直接的方法,从target降到1,如果是奇数就减一,偶数就除2 1 public static void main(String[] args) { 2 int a = shortest(17); 3 System.out.println(a)... 阅读全文
posted @ 2015-03-09 11:54 neverlandly 阅读(675) 评论(0) 推荐(0)
Twitter OA prepare: even sum pairs
摘要: 思路:无非就是扫描一遍记录奇数和偶数各自的个数,比如为M和N,然后就是奇数里面选两个、偶数里面选两个,答案就是M(M-1)/2 + N(N-1)/2 阅读全文
posted @ 2015-03-09 11:51 neverlandly 阅读(471) 评论(0) 推荐(0)
Twitter OA prepare: K-complementary pair
摘要: 2sum的夹逼算法,需要sort一下。本身不难,但是tricky的地方在于允许同一个数组元素自己跟自己组成一个pair,比如上例中的[5, 5]。而且数组本身就允许值相等的元素存在,在计算pair时,算成不同的pair,比如数组是[3,3],K=6,这时的pair有[0, 0], [0, 1], [... 阅读全文
posted @ 2015-03-09 11:50 neverlandly 阅读(468) 评论(0) 推荐(0)
Twitter OA prepare: Anagram is A Palindrome
摘要: Algorithm:Count the number of occurrence of each character.Only one character with odd occurrence is allowed since in a palindrome maximum number of c... 阅读全文
posted @ 2015-03-09 11:47 neverlandly 阅读(393) 评论(0) 推荐(0)
Twitter OA prepare: Visit element of the array
摘要: 分析:就是建立一个boolean array来记录array里面每个元素的访问情况,遇到访问过的元素就停止visiting,返回未访问的结点个数 1 public int visiting(int[] A, int N) { 2 if (A==null || A.length==0) ret... 阅读全文
posted @ 2015-03-09 11:41 neverlandly 阅读(362) 评论(0) 推荐(0)
Lintcode: Longest Common Substring
摘要: Given two strings, find the longest common substring.Return the length of it.NoteThe characters in substring should occur continiously in original str... 阅读全文
posted @ 2015-03-09 11:33 neverlandly 阅读(444) 评论(0) 推荐(1)
Lintcode: Longest Common Subsequence
摘要: Given two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.ExampleFor "ABCD" and "EDCA", the LCS is "A" (... 阅读全文
posted @ 2015-03-09 08:11 neverlandly 阅读(733) 评论(0) 推荐(1)
Lintcode: Kth Prime Number (Original Name: Ugly Number)
摘要: Ugly number is a number that only have factors3,5and7.Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7.The ... 阅读全文
posted @ 2015-03-09 05:28 neverlandly 阅读(1528) 评论(0) 推荐(0)
Lintcode: Kth largest Element
摘要: Find K-th largest element in an array.NoteYou can swap elements in the arrayExampleIn array [9,3,2,4,8], the 3rd largest element is 4In array [1,2,3,4... 阅读全文
posted @ 2015-03-09 03:49 neverlandly 阅读(1610) 评论(0) 推荐(0)
2015年3月7日
Lintcode: k Sum
摘要: Given n distinct positive integers, integer k (k i) res[i][j][t] = 0;18 else res[i][j][t] = res[i-1][j][t];19 ... 阅读全文
posted @ 2015-03-07 05:22 neverlandly 阅读(539) 评论(0) 推荐(0)
VMware Coding Challenge: The Heist
摘要: 类似BackpackII问题 1 static int maximize_loot(int[] gold, int[] silver) { 2 int[][] res = new int[gold.length+silver.length+1][10001]; 3 ... 阅读全文
posted @ 2015-03-07 03:50 neverlandly 阅读(310) 评论(0) 推荐(0)
VMware Coding Challenge: Removing Duplicates Entries
摘要: 1 static LinkedListNode removeDuplicates(LinkedListNode list) { 2 LinkedListNode cur = list; 3 HashSet set = new HashSet(); 4 ... 阅读全文
posted @ 2015-03-07 03:37 neverlandly 阅读(290) 评论(0) 推荐(0)
VMware coding Challenge: Coin Toss Betting
摘要: 1 static int CoinTossEndAmount(int betAmount, String coinTossResults) { 2 if (betAmount <=0 || coinTossResults.length() == 0) return betA... 阅读全文
posted @ 2015-03-07 03:33 neverlandly 阅读(304) 评论(0) 推荐(0)
2015年3月5日
Lintcode: k Sum II
摘要: Given n unique integers, number k (1> kSumII(int A[], int k, int target) { 9 // write your code here10 ArrayList> res = new ArrayList>... 阅读全文
posted @ 2015-03-05 06:51 neverlandly 阅读(1198) 评论(0) 推荐(0)
Lintcode: Interleaving Positive and Negative Numbers
摘要: Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.NoteYou are not necessary to keep ... 阅读全文
posted @ 2015-03-05 06:14 neverlandly 阅读(1090) 评论(0) 推荐(1)
Lintcode: Insert Node in a Binary Search Tree
摘要: Given a binary search tree and a new tree node, insert the node into the tree. You should keep the tree still be a valid binary search tree.ExampleGi... 阅读全文
posted @ 2015-03-05 05:00 neverlandly 阅读(1258) 评论(0) 推荐(0)
2015年3月4日
Amazon OA
摘要: Remove Duplicates from unsorted array,它的错误在于9-10行k out of bound,改成下面这样就没问题了 1 public class removeDuplicates { 2 public static int[] remove(int[] a... 阅读全文
posted @ 2015-03-04 07:01 neverlandly 阅读(1267) 评论(0) 推荐(0)
2015年3月1日
Leetcode: Best Time to Buy and Sell Stock IV
摘要: 这道题在Best Time to Buy and Sell Stock III做过,那道题只是把k取了2而已 递推式依然是 local[i][j]=max(global[i-1][j-1]+max(diff,0),local[i-1][j]+diff), global[i][j]=max(local 阅读全文
posted @ 2015-03-01 12:40 neverlandly 阅读(3456) 评论(0) 推荐(0)
Leetcode: Reverse Words in a String II
摘要: 这道题要求in-place做法,不能使用extra space, 那么,做法跟Rotate Array那道题非常相似 (1)reverse the whole array (2)reverse each subarray seperated by ' ' 注意不要忘了reverse最后一个word 阅读全文
posted @ 2015-03-01 07:49 neverlandly 阅读(6587) 评论(0) 推荐(0)
Leetcode: Repeated DNA Sequence
摘要: Naive 方法就是两层循环,外层for(int i=0; i<=s.length()-10; i++), 内层for(int j=i+1; j<=s.length()-10; j++), 比较两个字符串s.substring(i, i+10)和s.substring(j, j+10)是否equal 阅读全文
posted @ 2015-03-01 07:31 neverlandly 阅读(471) 评论(1) 推荐(0)
Leetcode: Rotate Array
摘要: Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:... 阅读全文
posted @ 2015-03-01 05:19 neverlandly 阅读(1718) 评论(0) 推荐(0)
2015年2月27日
VMware coding Challenge:Date of Weekday
摘要: 这道题再次证明了这种细节的题目,画个图容易搞清楚 1 import java.util.Scanner; 2 3 4 public class Solution2 { 5 static int DateOfWeekday(int date, int weekday) { 6 ... 阅读全文
posted @ 2015-02-27 14:09 neverlandly 阅读(508) 评论(0) 推荐(0)
VMware Coding Challenge: Possible Scores && Summary: static
摘要: Combination Sum I 那道题的变体 1 /* 2 * Complete the function below. 3 */ 4 5 static int is_score_possible(int score, int[] increments) { 6 A... 阅读全文
posted @ 2015-02-27 12:22 neverlandly 阅读(428) 评论(0) 推荐(0)
2015年2月21日
Summary: rand5构造rand7
摘要: 给一个方法,比如 rand5(), 它能够等概率生成 1-5 之间的整数。 所谓等概率就是1,2,3,4,5 生产的概率均为 0.2 。现在利用rand5(), 构造一个能够等概率生成 1- 7 的方法。这里有两个特别重要的点,一是 如果 rand5() + rand5(), 我们能够产生一个均匀分... 阅读全文
posted @ 2015-02-21 04:37 neverlandly 阅读(521) 评论(0) 推荐(0)
2015年2月10日
Summary: 书架问题
摘要: Consider the problem of storing n books on shelves in a library. The order of the books is fixedby the cataloging system and so cannot be rearraged. T... 阅读全文
posted @ 2015-02-10 05:29 neverlandly 阅读(886) 评论(0) 推荐(0)
2015年2月8日
Summary: sorting Algorithms
摘要: Insertion sortis a simplesorting algorithmthat builds the finalsorted array(or list) one item at a time. It is much less efficient on large lists than... 阅读全文
posted @ 2015-02-08 12:01 neverlandly 阅读(364) 评论(0) 推荐(0)
Lintcode: Heapify && Summary: Heap
摘要: Heap的介绍1,介绍2,要注意complete tree和full tree的区别, Heap是complete tree;Heap里面 i 的 children分别是 i*2+1 和 i*2+2,i 的 parent是 (i-1)/2 Heapify的基本思路就是:Given an array 阅读全文
posted @ 2015-02-08 06:57 neverlandly 阅读(2040) 评论(0) 推荐(0)
2015年2月7日
Lintcode: Implement Queue by Stacks
摘要: As the title described, you should only use two stacks to implement a queue's actions.The queue should support push(element), pop() and top() where po... 阅读全文
posted @ 2015-02-07 07:51 neverlandly 阅读(440) 评论(0) 推荐(1)
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 21 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3