摘要:
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./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * nex... 阅读全文
posted @ 2014-01-06 11:39
23lalala
阅读(117)
评论(0)
推荐(0)
摘要:
Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place./** *O(1)空间解法,把每行的第一个元素和每列的第一个元素作为改行列是否清零的标志 **/public class Solution { public void setZeroes(int[][] matrix) { if (matrix==null) { return; } int row = matrix.length; in... 阅读全文
posted @ 2014-01-06 11:39
23lalala
阅读(97)
评论(0)
推荐(0)
摘要:
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.public class Solution { public void merge(int A[], int m, int B[], int n) ... 阅读全文
posted @ 2014-01-06 11:39
23lalala
阅读(109)
评论(0)
推荐(0)
摘要:
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)
摘要:
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)
摘要:
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)

浙公网安备 33010602011771号