上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页
摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Sol... 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(102) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(86) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(89) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321public class Solution { public int reverse(int x) { int ret = 0; int i = 10; int x_cpy = x; ArrayList array = new ArrayList(); while (x!=0) { int di = x%10; ... 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(60) 评论(0) 推荐(0) 编辑
摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8/** * Definition for 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(74) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.public class Solution { public int roman2Int(char c) { switch (c) { case 'I': return 1; case 'V': return 5; case 'X': ... 阅读全文
posted @ 2014-01-06 11:37 23lalala 阅读(106) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}./** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListN... 阅读全文
posted @ 2014-01-06 11:36 23lalala 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next... 阅读全文
posted @ 2014-01-06 11:19 23lalala 阅读(119) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note:Recursive solution is trivial, could you do it iteratively?/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2014-01-06 11:18 23lalala 阅读(104) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2014-01-06 11:17 23lalala 阅读(157) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页