摘要: 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.Subscribe... 阅读全文
posted @ 2015-11-22 16:55 0giant 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2015-11-19 17:40 0giant 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 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 cli... 阅读全文
posted @ 2015-11-19 15:24 0giant 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2015-11-18 14:10 0giant 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Reverse a singly linked list对于这种可以修改值的,把值逆序就可以了。。。。用vector存,然后逆序读。都忘了指针怎么赋值初始化了。*p=&head; 1 /** 2 * Definition for singly-linked list. 3 * struct Li... 阅读全文
posted @ 2015-11-17 19:03 0giant 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.题目虽短,但是难度还是在那里的。首先,我们需要明白罗马数字是怎么计数的,当你明白了这个就... 阅读全文
posted @ 2015-11-17 17:03 0giant 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 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 ... 阅读全文
posted @ 2015-11-16 16:12 0giant 阅读(200) 评论(0) 推荐(0) 编辑
摘要: ---恢复内容开始---【一】一共有n个人,有m条跳绳,我们如何分配组以及组员数,使得每组的人数相差最少,例如输入9个人,8条跳绳,最佳分配是5,4;刚开始并没有理解题的意思,情急之下,百度为上。看到一道和这道题非常类似的题目。输入两个数,人数为n,跳绳数为m。首先,加入人数小于m分成1组就好了,如... 阅读全文
posted @ 2015-11-16 13:07 0giant 阅读(530) 评论(0) 推荐(0) 编辑
摘要: 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 i... 阅读全文
posted @ 2015-11-16 10:23 0giant 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 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 arr... 阅读全文
posted @ 2015-11-13 13:13 0giant 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 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 = ... 阅读全文
posted @ 2015-11-12 17:18 0giant 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, give... 阅读全文
posted @ 2015-11-12 15:55 0giant 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2015-11-11 15:59 0giant 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRang... 阅读全文
posted @ 2015-11-11 15:13 0giant 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1比较简单,二叉树里的题其实有点举一反三的意思,很多题会一道就差不多了。递归的反... 阅读全文
posted @ 2015-11-09 16:24 0giant 阅读(132) 评论(0) 推荐(0) 编辑