随笔分类 - 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
阅读全文
摘要: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: [
阅读全文
摘要: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
阅读全文
摘要: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.
阅读全文
摘要:The "Hamming distance" between two integers is the number of positions at which the corresponding bits are different. Given two integers and , calcula
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Given a string containing just the characters , , , , and , determine if the input string is valid. The brackets must close in the correct order, and
阅读全文
摘要: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
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 首先判断最小长度,然后就是遍历。记得内部循环后置零 java public String longestCommonPrefi
阅读全文
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 自己写的代码第一次没有AC,超时。第二遍就莫名其妙通过了 附上相似代码
阅读全文
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.
阅读全文
摘要: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
阅读全文
浙公网安备 33010602011771号