- 博客(17)
- 资源 (2)
- 收藏
- 关注
原创 [Leetcode] 292. Nim Game
题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will b
2016-05-14 09:50:58 289
原创 [Leetcode] 278. First Bad Version
题目: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based o
2016-05-13 20:32:05 204
原创 [Leetcode] 13. Roman to Integer
题目: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路: 根据规则1,2,3具体代码如下:public class Solution { public int romanToInt(String s) {
2016-05-13 14:20:07 188
原创 [Leetcode] 12. Integer to Roman
题目: 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 M[] = {"",
2016-05-13 11:23:02 163
原创 [Leetcode] 318. Maximum Product of Word Lengths
题目: Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case
2016-05-13 11:17:09 236
原创 [Leetcode] 268. Missing Number
题目: Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in
2016-05-13 09:44:38 278
原创 [Leetcode] 143. Reorder List
题目: Given a singly linked list L: 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,
2016-05-09 09:05:35 195
原创 Leetcode 061 Rotate List
题目: Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.思路: 1)遍历链表得到链表长度 2)找到要调整位置的链表结点的前一个
2016-05-08 11:59:25 249
原创 Leetcode 82. Remove Duplicates from Sorted List II
题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1
2016-05-08 11:35:24 169
原创 Leetcode 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh
2016-05-08 11:03:31 227
原创 [Leetcode] 92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note: Given m, n satisfy the following co
2016-05-06 09:42:42 497
原创 Leetcode 86. Partition List
题目: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2016-05-05 11:07:56 355
原创 Leetcode 142. Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.思路:设置两个指针,一个指针每次向后移一步,一个指针一次向后移2步,假设存在圈,则两个指针总有相遇的时候。 设圈长r,设相遇时
2016-05-05 09:47:42 212
原创 Leetcode 147. Insertion Sort List
题目: Sort a linked list using insertion sort.思路:把链表设置一个伪头结点(方便后面的插入操作),从第二个结点开始从真正的头结点开始比较,遇到比它大的结点,就把该结点插入这个节点之前具体代码:public ListNode insertionSortList(ListNode head) { if(head == null){
2016-05-04 22:10:20 184
原创 Leetcode 2. Add Two Numbers
题目: 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
2016-05-04 15:04:18 221
原创 Leetcode 328. Odd Even Linked List
题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-05-04 11:07:23 224
原创 Leetcode 141 Linked List Cycle
题目: Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space? 思路: 1)将遍历过的结点都指向头结点,遍历一个结点之前判断该结点的next的next的结点是否是头结点,如果是头结点的话,则存在环 2)设置两个指针,步数不同 如
2016-05-04 10:42:04 224
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人