`
文章列表
Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.   public ListNode deleteDuplicates(ListNode head) { ListNode p = head; while(p != null && ...
发信人: byday (眉飞色舞), 信区: JobHunting 标  题: 中年马工的跳槽路 发信站: BBS 未名空间站 (Thu Aug  7 17:16:46 2014, 美东)   呵呵,从版上学到不少东西,我也把我的经历写出来,希望能对大家有帮助。   背景: 名校 PhD + 10 年 EDA (非internet)工作经验。   跳槽原因: 公司遇到太多politics,部门90%都是印度人,觉得没多少上升空间了。其实这10 年,公司部门对我都不错,所以我呆了这么久。   跳槽过程: 准备了2,3个月。从6月开始投简历,7月末决定去Face ...
Given matrix MxN of 0s and 1s, return and output all groups of adjacent 1s in form of (row,col)... 1s are considered adjacent if they are adjacent horizontally or vertically. 1 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 1 1 1 0 1 0 1 0 Output: A: (0,0)(1,0)(0,1)(1,1)(1,2)(1,3)(0,3) B: (0,5)(1,5)(2,4)(2, ...
Given a sequence, find the length of the longest palindromic subsequence in it. For example, if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic subseuqnce in it. “BBBBB” and “BBCBB” are also palindromic subsequences of the given sequence, but no ...
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m + n) space, but still not the best solution.Could you devise a consta ...
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"   Corner Cases:   Did you consider the case where path = 
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100".   public String addBinary(String a, String b) { StringBuilder sb = new StringBuilder(); int m = a.length()-1, n = b.length()-1; int carry = 0; ...
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case.   public List<String> anagrams(String[] strs) { List<String> result = new ArrayList<>(); Map<String, List<String>> map = new HashMap<>() ...
给一个整数,表示成n个整数的平方和,n最小,求n。10017 = 100^2 + 4^2 + 1 --> n = 3   这道题的快速解法要牵扯到数学定理了。   Lagrange's four-square theorem Every natural number can be represented as the sum of four integer squares.   Legendre's three-square theorem Let m, n be integers equal to or greater than 0. If N = 4m(8n+7), ...
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()", which has length = 2. Another example is ")()())", where the longest valid ...
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and 
Write a function to validate whether the input is valid UTF-8. Input will be string or byte array, output should be true or false. UTF-8是一种变长的编码方式。它可以使用1~4个字节表示一个符号,根据不同的符号而变化字节长度。UTF-8的编码规则很简单,只有二条:1)对于单字节的符号,字节的第一位设为0,后面7位为这个符号的unicode码。因此对于英语字母,UTF-8编码和ASCII码是相同的。2)对于n字节的符号(n>1),第一个字节的前n ...
Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors such that no more than 2 adjacent fence posts are painted with the same color. 因为题目要求是不超过两个相邻的栅栏有同样颜色,所以可以把题目分解一下:设T(n)为符合要求的染色可能总数,S(n)为最后两个相邻元素为相同颜色的染色可能数,
Find the second largest number in a given array.Return 0 if the given array has no second largest number.   public int secondLargest(int[] arr) { if(arr.length<2) return 0; int first = Math.max(arr[0], arr[1]); int second = Math.min(arr[0], arr[1]); for(int i=2; i<arr.len ...
Given an integer between 0 and 999,999, print an English phrase that describes the integer (eg, “One Thousand, Two Hundred and Thirty Four”)   http://ideone.com/Q1AT1p vector<string> under20 = {"Zero", "One", "Two", "Three", "Four", "F ...
Global site tag (gtag.js) - Google Analytics