- 博客(22)
- 收藏
- 关注
转载 [leetcode 190]Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101
2015-03-27 14:42:31
282
转载 [leecode 190]Reverse digits of an integer.Reverse digits of an integer.
反转很容易实现,难的是对异常case的考虑。比如如果没有示例,你是否会考虑到负数的情况。10,100这个可以在写代码前问下面试官或者在代码里写明,表示你考虑到了这种情况。然后就是有可能溢出!!Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -
2015-03-18 22:02:01
474
原创 [leetcode 191]Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000
2015-03-18 21:17:42
280
转载 [leetcode 168]Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 考虑下这个正整
2015-03-17 14:38:27
310
转载 [leetcode #3待续]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo
2015-03-17 13:11:09
312
转载 [leetcode #20 stack]Valid Parentheses
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 va
2015-03-14 19:12:48
250
转载 [leetcode160链表]Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-03-12 17:25:31
378
转载 [leetcode 147]Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * };
2015-03-12 16:31:14
305
翻译 [leetoce 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
2015-03-12 14:56:37
405
转载 [leetcode141 142]Linked List Cycle I II
1 Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?如何求环的长度,记住碰撞点的指针,让slow指针不停向后遍历,当再次回到碰撞点时走过的距离就是环的长度。碰撞点到环节点 = 头结点到环节点设环外
2015-03-12 13:22:49
305
转载 [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
2015-03-12 11:46:50
251
转载 [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
2015-03-12 11:14:50
302
转载 [leetcode 83]Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.class Solut
2015-03-11 18:47:11
297
转载 [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-
2015-03-11 17:44:50
289
转载 [leetcode #61]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.需要考虑k大于链表长度,主流的方法是将链表成环然后找到位置然后断环
2015-03-11 17:00:37
292
转载 [leetcode #25]Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is
2015-03-11 16:13:01
343
转载 [Leetcode 24 链表]Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2015-03-11 14:51:00
351
转载 [#23 leetcode]Merge k Sorted Lists
方法1:一开始想到的方法,每次都要遍历一遍vector.时间复杂度很高,如果每个链表都只有一个元素,但是有很多个链表。class Solution {public: ListNode *mergeKLists(vector &lists) { ListNode head(0); ListNode *p = &head; ListNode *
2015-03-11 14:14:39
309
转载 leetcode[21 链表]Merge Two Sorted Lists
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.很简单的题目,第一次刷的时候不知道加个头结点,代码如下,自己写的再看都觉得很难阅读,不够清晰。因为第一个节点是
2015-03-10 21:01:07
404
转载 leetcode[#19 链表 标尺]Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the
2015-03-10 16:59:34
430
转载 leetcode[#2 链表]Add Two Numbers
难点主要是考虑进位,然后两个链表的长度不一定相等,这里用三元运算符可以使代码看起来更加简洁,然后自己是做了个判断记住头指针的位置。看别人的代码,可以new一个元素,但是要注意释放,更巧妙的方法是直接定义一个临时变量,虽然函数结束之后这个临时变量会自动销毁,但是它里面存的地址是始终有效的。然后有递归的解法,因为自己一直对递归不是很懂,加进来看下。class Solution {public:
2015-03-10 16:13:50
275
转载 大端小端 简单的程序判断
http://blog.youkuaiyun.com/zhaoshuzhaoshu/article/details/376008571. 什么是大端,什么是小端:所谓的大端模式,是指数据的低位保存在内存的高地址中,而数据的高位,保存在内存的低地址中;所谓的小端模式,是指数据的低位保存在内存的低地址中,而数据的高位保存在内存的高地址中。2.为什么会有大小端:
2015-02-12 16:03:17
817
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人