摘要:
Divide two integers without using multiplication, division and mod operator.---public class Solution { public int divide(int dividend, int divisor) { boolean sign1 = dividend >=0; boolean sign2 = divisor >=0; long a = Math.abs((long)dividend); long b = ... 阅读全文
posted @ 2013-09-02 05:24
LEDYC
阅读(130)
评论(0)
推荐(0)
摘要:
mplement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.---public class Solution { public String strStr(String haystack, String needle) { if(haystack == null || needle == null) return null; int... 阅读全文
posted @ 2013-09-02 04:51
LEDYC
阅读(165)
评论(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.---Similar to 25, remove dup from a sorted array---public class Solution { public int removeElement(int[] 阅读全文
posted @ 2013-09-02 04:48
LEDYC
阅读(273)
评论(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 @ 2013-09-02 04:07
LEDYC
阅读(140)
评论(0)
推荐(0)
摘要:
Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be changed.Only constant memory is allowed 阅读全文
posted @ 2013-09-02 03:59
LEDYC
阅读(181)
评论(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.---Solution1: Interat 阅读全文
posted @ 2013-09-02 02:35
LEDYC
阅读(282)
评论(0)
推荐(0)
浙公网安备 33010602011771号