LeetCode – String to Integer (atoi) (Java)

Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Analysis The following cases should be considered for this problem: 1. null or empty string 2. white spaces 3. +/- … Read more

LeetCode – 3Sum

Problem: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c) … Read more

LeetCode – Merge Intervals

Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. Analysis The key to solve this problem is defining a Comparator first to sort the arraylist of Intevals. Java Solution public List<Interval> merge(List<Interval> intervals) { if(intervals == null || intervals.size()<=1){ return intervals; }   Collections.sort(intervals, Comparator.comparing((Interval itl)->itl.start));   List<Interval> result … Read more

LeetCode – Regular Expression Matching (Java)

Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p) Some examples: isMatch(“aa”,”a”) return false isMatch(“aa”,”aa”) return true isMatch(“aaa”,”aa”) … Read more

AMD versus Intel: Successes and pitfalls of their processor architectures – (3) Related Work and Conclusion

III. Related work

This paper is a summary of facts about different processors. Wikipedia has collected many individual concepts of computer architecture and various concepts of Intel and AMD processors can be found. For example, AMD timeline, Intel processor microarchitecture, etc.

Read more

AMD versus Intel: Successes and pitfalls of their processor architectures – (1) Abstract and Introduction

AMD versus Intel: Successes and pitfalls of their processor architectures

Warning: This article is boring if you are not interested in computer architecture design. But if you are taking Computer Architecture class, this can be a very good study guide for you.

Read more

小白Moto G北美版刷中文三步走

最近更新: 2013å¹´12月17æ—¥ Moto G 11月底在北美低调上市,8Gå’Œ16G售价分别为179美元和199美元,分别有美国版和全球版本,差别在于北美版多了一个GSM频段。如此亲民的价格让它一举成为低端智能机市场的新宠,关于MotoG会否在中国大陆上市,Google官方称,由于中国大陆无法使用Google服务,因此MotoG不会在大陆上市。待第一批吃螃蟹的人拿到真机,才发现北美版MotoG全球版内置语言只有四种,包括英文,西班牙语,法语和葡萄牙语。这无异于一盆冷水浇在心头,如何拥有中文版MotoG呢? 首先有人想到让Antroid自动升级更新语言包,MotoG自带Antroid 4.3 Jelly Bean系统,如果系统升级到Antroid 4.4 Kitkat,MotoG是否就能自动拥有完整语言包了呢?事实证明,语言问题的关键在于北美版MotoGçš„Stock Rom不同,所以要在北美版增加中文语言,只剩下刷机一条路了, 所幸早前在英国上市的MotoG拥有完整语言包,所以我们只要安装上英国版的Stock Rom就能使用中文了。下面我们就来看一下一个小白的三步走刷机攻略。 第一步  解锁手机 在这一步,你需要一个motorola 或者google的账户。 首先进入Moto官网手机解锁页面。 第一页是Motorola的警告,一旦解锁,你将不再拥有Motorola的保修,无所畏惧地按下“NEXT”,通过google或motorola账户登录,接下来就是解锁了。作为一个小白,我肯定不会有Antroid SDKå’ŒMotorola USB Driver,根据需要选择Windows, MAC OS或者Linux系统的版本进行下载。解压缩和安装完毕后,打开command prompt(Windows)或者terminal(MAC OS),到已解压缩的Antroid sdk目录下,进入/sdk/platforms-tools/,确认fastboot这个文件在当前文件夹中。 拿出MotoG,重启进入fastboot模式(先关机,然后长按解锁键和调低音量的按钮),进入fastboot模式后,连接电脑和手机。 在prompt或termial输入 $ fastboot oem get_unlock_data 屏幕会返回一串五行的unlock key,复制这段key, 注意不要包含空格或者(bootloader),粘贴到之前moto网页的输入栏,按下 Can my device be unlocked? 如果手机不能被解锁,网页底部会显示 REQUEST UNLOCK KEY, 按下那个按钮,你的邮箱10秒钟后会收到一串unlock key。 然后在命令行输入: $ fastboot oem get_unlock_data 把get_unlock_data替换成邮件收到的key,敲人回车后,手机就已成功解锁,重启后手机会显示 第二步 … Read more

LeetCode – Median of Two Sorted Arrays (Java)

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Java Solution This problem can be converted to the problem of finding kth element, k is (A’s length + B’ Length)/2. If any of … Read more

LeetCode – Clone Graph (Java)

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. Java Solution 1 – DFS HashMap<Node, Node> map = new HashMap<>(); public Node cloneGraph(Node node) { map.put(node, new Node(node.val, new ArrayList<>()));   for(Node neighbor: node.neighbors){ if(map.containsKey(neighbor)){ map.get(node).neighbors.add(map.get(neighbor)); }else{ map.get(node).neighbors.add(cloneGraph(neighbor)); } }   return map.get(node); }HashMap<Node, Node> map … Read more

LeetCode – Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that only one letter can be changed at a time and each intermediate word must exist in the dictionary. For example, given: start = “hit” end = “cog” dict = [“hot”,”dot”,”dog”,”lot”,”log”] One shortest transformation … Read more

LeetCode – Reverse Integer

LeetCode – Reverse Integer: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 1. Naive Method We can convert the integer to a string/char array, reverse the order, and convert the string/char array back to an integer. However, this will require extra space for the string. It … Read more