随笔分类 -  algorithm

many interesting algorithm which may be used later
摘要:题目: 思路: 第一种方法:利用二分查找的思想。判断一个数的中间值的平方是不是等于这个数是的话直接返回,否则的话根据middle^2和x的大小确定Low和high的值。这里有注意的一个点就是while的判断条件,如果high-low>1的话才可以继续循环。否则的话会陷入死循环。 以下是第一种方法的j 阅读全文
posted @ 2018-06-30 00:09 whatyouknow123 阅读(323) 评论(0) 推荐(0)
摘要:思路:用两个hash表来存储pattern中每个字母对应的word和单词中每个word对应的pattern中的字母。 以下是我在leetcode上提交的结果: leetcode上的题目的地址是:https://leetcode.com/problems/word-pattern/descriptio 阅读全文
posted @ 2018-06-22 22:37 whatyouknow123 阅读(336) 评论(0) 推荐(0)
摘要:思路:有两种方法。第一种方法是用两重循环,遍历计算所有可能的target的值,这是比较朴素的方法。另外一种方法是利用hash表。现将所有的值保存到hash表中,然后计算target减去当前的value的值,然后这个值在hash表中并且不是当前的value,那么就找到了答案。 第一种方法: 第二种方法 阅读全文
posted @ 2018-06-22 18:04 whatyouknow123 阅读(190) 评论(0) 推荐(0)
摘要:题目: 首先要看懂题目。这个题目的意思就是你要找到一个单词,这个单词以第一个字母开头的连续子串都在这个单词数组中。并且如果有多个符合条件的单词那你就选择其中字典序最小的那一个。 然后是思路。首先将单词数组按照字典序进行排序,然后从后向前,找到其中符合条件的单词。【这样做的目的是为了保证result数 阅读全文
posted @ 2018-06-20 20:51 whatyouknow123 阅读(510) 评论(0) 推荐(0)
摘要:题目: 有两种思路,一种是采用简单的搜索,可以一个一个的向上检索,直到匹配;另外一种是采用折半查找,如果存在array[middle]==target那么直接返回target的位置,否则的话,找到low和high相等的位置,判断数组中此位置的值是否大于等于target,是的话就直接返回low,否则返 阅读全文
posted @ 2018-06-20 10:30 whatyouknow123 阅读(164) 评论(0) 推荐(0)
摘要:# 题目 读《剑指offer》的启发 ## 修改简历 之前简历中的项目介绍,写的不好。应该要按照STAR的原则,进行语言的重新组织。 ## 准备问题 为什么选择某个职位问与招聘的职位或者项目相关的问题。 ## 问编程时候需要注意的问题 - 不要马上写代码 - 先写出流程图 - 要确定边界情况,异常输 阅读全文
posted @ 2018-05-10 22:17 whatyouknow123 阅读(167) 评论(0) 推荐(0)
摘要:前言: 二分搜索是一个非常常见的面试题目,它具有非常广泛的用途。熟练的掌握二分搜索的基本形式和他的变式是非常重要的。接下来我们将使用java实现一些常见的有关二分搜索的问题。 具体内容: 1.二分搜索的基本形式:在一个有序的数组中查找k,如果k存在的话就返回k的下标,否则就返回-1 基本的二分搜索要 阅读全文
posted @ 2018-05-09 21:10 whatyouknow123 阅读(460) 评论(0) 推荐(0)
摘要:description: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If 阅读全文
posted @ 2017-09-16 16:01 whatyouknow123 阅读(263) 评论(0) 推荐(0)
摘要:Description: Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations: [ [1,2,3], 阅读全文
posted @ 2017-09-10 16:36 whatyouknow123 阅读(171) 评论(0) 推荐(0)
摘要:Description: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums t 阅读全文
posted @ 2017-09-09 09:28 whatyouknow123 阅读(169) 评论(0) 推荐(0)
摘要:Descirption: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate 阅读全文
posted @ 2017-09-09 09:09 whatyouknow123 阅读(134) 评论(0) 推荐(0)
摘要:description: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate e 阅读全文
posted @ 2017-09-07 09:42 whatyouknow123 阅读(167) 评论(0) 推荐(0)
摘要:Description: Write a function to find the longest common prefix string amongst an array of strings. Thoughts: 1.定义一个结果字符串result=""; 2.如果List的长度为0,那么直接 阅读全文
posted @ 2017-09-06 09:10 whatyouknow123 阅读(161) 评论(0) 推荐(0)
摘要:descripte problem: there is an array,at the first it is sorted,but for som reason, it was rotated at some pivot unknown to you beforehand.then you sho 阅读全文
posted @ 2017-04-24 09:52 whatyouknow123 阅读(139) 评论(0) 推荐(0)
摘要:problem description: there is four number list named A,B,C,D; now you should out put the num of tuples which statisfy A[i] +B[j]+C[k]+D[l] =0 i.e: 以上的 阅读全文
posted @ 2017-04-23 22:04 whatyouknow123 阅读(170) 评论(0) 推荐(0)
摘要:problem description: remove the nth node from the end of the list for example: given: 1->2->3 n = 1 return: 1->2 thought: first:you should know the le 阅读全文
posted @ 2017-04-18 10:01 whatyouknow123 阅读(178) 评论(0) 推荐(0)
摘要:problem description: this is the addition about the 3sum,you can use the method of solve the 3sum. given a integer and the target,you should return th 阅读全文
posted @ 2017-04-18 09:55 whatyouknow123 阅读(131) 评论(0) 推荐(0)
摘要:problem description: you should change the given digits string into possible letter string according to the phone keyboards. i.e. input '23' output [' 阅读全文
posted @ 2017-04-13 10:37 whatyouknow123 阅读(403) 评论(0) 推荐(0)
摘要:problem describe: given a string , first find the first word which is not white space;then there will be an optional '+' or '-', but the given the tes 阅读全文
posted @ 2017-04-10 12:45 whatyouknow123 阅读(246) 评论(0) 推荐(0)
摘要:problem description: given a string s, you shou find the longest palindromic substring in there for example:input :"ssaass" ouput:"ssaass" one solutio 阅读全文
posted @ 2017-04-07 12:41 whatyouknow123 阅读(185) 评论(0) 推荐(0)