上一页 1 2 3 4 5 6 7 ··· 28 下一页
摘要: Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: ... 阅读全文
posted @ 2017-12-03 11:22 apanda009 阅读(142) 评论(0) 推荐(0) 编辑
摘要: array不是sorted的,里面可能有负数。解法也是从两边往中间搞,用两个数组left和right存原数组从左向右和从右向左的元素和。然后按index来比较left和right两个数组里的元素,有相等的就是balance point. 阅读全文
posted @ 2017-12-03 10:38 apanda009 阅读(173) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.第二遍做法:时间复杂度应该是O(m*n),m表示字符串的最大长度,n表示字符串的个数,空间复杂度应该是O(m),即字符串的长度 public class Solution { public String longest... 阅读全文
posted @ 2017-12-03 10:27 apanda009 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 二分法逼近,然后找个误差值到时候跳出循环 阅读全文
posted @ 2017-12-03 10:12 apanda009 阅读(165) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm 阅读全文
posted @ 2017-12-03 09:52 apanda009 阅读(227) 评论(0) 推荐(0) 编辑
摘要: Given a tree string expression in balanced parenthesis format:[A[B[C][D]][E][F]].Construct a tree and return the root of the tree. A / | \ B E F / \ C 阅读全文
posted @ 2017-12-03 09:28 apanda009 阅读(160) 评论(0) 推荐(0) 编辑
摘要: private static String convertBinary(int sum) { StringBuffer binary = new StringBuffer(); while (true) { binary.insert(0, sum % 2); sum = sum / 2... 阅读全文
posted @ 2017-12-03 08:53 apanda009 阅读(173) 评论(0) 推荐(0) 编辑
摘要: we start from the leftmost point (or point with minimum x coordinate value) and we keep wrapping points in counterclockwise direction. The big questio 阅读全文
posted @ 2017-12-03 08:37 apanda009 阅读(299) 评论(0) 推荐(0) 编辑
摘要: 我就想了个递归, 还是没有区分掉一些重复的情况,worst case O(2^n)基本同暴力解 Map> allSubSet = new HashMap(); Set getAllPalidrome(String s, int x, int y){ int ind = x * s.length() + y; if(allSubSet.constainsKey(ind)) return a... 阅读全文
posted @ 2017-12-03 07:41 apanda009 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 每次移动3个pointer 里面最小的那个就好了。记录整个过程找最近的3个数。3个数之中median没意义,距离主要由最小和最大决定。基本就是这个思路。很快编完就过了编程阶段。 阅读全文
posted @ 2017-12-03 07:27 apanda009 阅读(239) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 28 下一页