上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页
摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) 阅读全文
posted @ 2014-01-06 11:39 23lalala 阅读(103) 评论(0) 推荐(0)
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } * * 麻烦的地方在于java里的array... 阅读全文
posted @ 2014-01-06 11:39 23lalala 阅读(137) 评论(0) 推荐(0)
摘要: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.public class Solution { public int removeElement(int[] A, int elem) { int n = A.length; for ... 阅读全文
posted @ 2014-01-06 11:39 23lalala 阅读(95) 评论(0) 推荐(0)
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4,−1,2,1]has the largest sum =6.public class Solution { public int maxSubArray(int[] A) { if (A.length==1) { ... 阅读全文
posted @ 2014-01-06 11:39 23lalala 阅读(99) 评论(0) 推荐(0)
摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed./** * Definition for 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(128) 评论(0) 推荐(0)
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public String intToRoman(int num) { String[] romans = {"M","CM","D","CD","C","XC","L","XL" 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(104) 评论(0) 推荐(0)
摘要: Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(125) 评论(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"()[]{}"are all valid but"(]"and"([)]"are not.pub 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(100) 评论(0) 推荐(0)
摘要: Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must be in non-descending order. (ie,a≤b≤c)The solution set must not contain duplicate triplets. For example, given array S... 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(115) 评论(0) 推荐(0)
摘要: Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, and A is 阅读全文
posted @ 2014-01-06 11:38 23lalala 阅读(88) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 13 下一页