随笔分类 -  LeetCode

算法很重要
摘要:Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. public int divide(int dividend, int di 阅读全文
posted @ 2017-11-22 14:12 binryang 阅读(86) 评论(0) 推荐(0)
摘要:Given n pairs of parentheses, write a function to generate all combinations of well formed parentheses. For example, given n = 3, a solution set is: [ 阅读全文
posted @ 2017-11-21 20:47 binryang 阅读(96) 评论(0) 推荐(0)
摘要:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic 阅读全文
posted @ 2017-11-21 15:55 binryang 阅读(110) 评论(0) 推荐(0)
摘要:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. 阅读全文
posted @ 2017-11-21 14:50 binryang 阅读(83) 评论(0) 推荐(0)
摘要:The "Hamming distance" between two integers is the number of positions at which the corresponding bits are different. Given two integers and , calcula 阅读全文
posted @ 2017-10-26 17:02 binryang 阅读(149) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example, Given , you should return the list as . Your algorithm should use 阅读全文
posted @ 2017-10-20 13:16 binryang 阅读(98) 评论(0) 推荐(0)
摘要:The count and say sequence is the sequence of integers with the first five terms as following: is read off as or . is read off as or . is read off as 阅读全文
posted @ 2017-10-16 16:43 binryang 阅读(117) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文
posted @ 2017-10-16 14:46 binryang 阅读(83) 评论(0) 推荐(0)
摘要:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or 1 if needle is not part of haystack. public int strStr(String 阅读全文
posted @ 2017-10-11 13:07 binryang 阅读(70) 评论(0) 推荐(0)
摘要:Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you 阅读全文
posted @ 2017-10-11 12:26 binryang 阅读(67) 评论(0) 推荐(0)
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo 阅读全文
posted @ 2017-09-28 12:13 binryang 阅读(72) 评论(0) 推荐(0)
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文
posted @ 2017-09-27 20:44 binryang 阅读(68) 评论(0) 推荐(0)
摘要:Given a linked list, remove the n th node from the end of list and return its head. For example, Note: Given n will always be valid. Try to do this in 阅读全文
posted @ 2017-09-26 09:04 binryang 阅读(89) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. java pub 阅读全文
posted @ 2017-09-22 16:18 binryang 阅读(85) 评论(0) 推荐(0)
摘要:Given a string containing just the characters , , , , and , determine if the input string is valid. The brackets must close in the correct order, and 阅读全文
posted @ 2017-09-22 15:19 binryang 阅读(90) 评论(0) 推荐(0)
摘要: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 o 阅读全文
posted @ 2017-09-19 13:32 binryang 阅读(109) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings. 首先判断最小长度,然后就是遍历。记得内部循环后置零 java public String longestCommonPrefi 阅读全文
posted @ 2017-09-15 14:38 binryang 阅读(91) 评论(0) 推荐(0)
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 自己写的代码第一次没有AC,超时。第二遍就莫名其妙通过了 附上相似代码 阅读全文
posted @ 2017-09-13 21:55 binryang 阅读(102) 评论(0) 推荐(0)
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 阅读全文
posted @ 2017-09-12 22:22 binryang 阅读(73) 评论(0) 推荐(0)
摘要:Given n non negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo 阅读全文
posted @ 2017-09-11 22:28 binryang 阅读(98) 评论(0) 推荐(0)