- 博客(16)
- 收藏
- 关注
原创 232. Implement Queue using Stacks
题目 Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front elemen
2016-03-31 10:49:12 238
原创 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. 分析 先创建一个空结点当做哨位结点,merge_tail指向合并链表的尾部,比较l1和l2,循环
2016-03-31 09:54:47 220
原创 231. Power of Two
题目 Given an integer, write a function to determine if it is a power of two. 分析 循环除2。 class Solution { public: bool isPowerOfTwo(int n) { if(n<=0) return false; if
2016-03-30 10:41:07 217
原创 202. Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the
2016-03-30 10:26:23 208
原创 263. Ugly Number
题目 Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not u
2016-03-29 16:05:24 222
原创 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. 分析 当前结点与下一个结点值比较
2016-03-29 15:51:56 272
原创 70. Climbing Stairs
题目 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 分析 有一段楼梯有10级台阶,规定每一步只
2016-03-29 15:36:01 239
原创 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
2016-03-28 11:21:20 229
原创 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 representatio
2016-03-28 10:41:21 223
原创 235. Lowest Common Ancestor of a Binary Search Tree
题目 Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is define
2016-03-28 10:00:15 270
原创 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. 分析 罗马字母向整数转换,小数在大数左边做减法,小数在大数右边做加法,倒序扫描字符串,用current_num保存上一次循环扫描的字符,map_it->sec
2016-03-24 20:53:26 274
原创 206. Reverse Linked List
题目 Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 分析 链表转向问题,通过遍历链表,将其拆分为已经转置和待转置两部分,改变next指针即可。 /** * Defin
2016-03-23 11:49:19 306
原创 169. Majority Element
题目 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority
2016-03-23 11:14:29 226
原创 217. Contains Duplicate
题目 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every elem
2016-03-21 16:25:45 285
原创 242. Valid Anagram
题目 Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. 分析 由于存在
2016-03-21 11:40:28 283
原创 Windows下安装ubuntu
安装过程详细参考以下链接 点击打开链接 以上过程安装完后是Ubuntu引导Windows,要修改成Windows引导Ubuntu参考以下内容 点击打开链接
2016-03-21 11:28:23 321
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人