- 博客(31)
- 收藏
- 关注
原创 #leetcode#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 element.empty(
2016-04-28 21:49:54 219
原创 #leetcode#110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2016-04-28 21:27:41 198
原创 #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
2016-04-28 21:00:11 239
原创 #leetcode#198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house
2016-04-27 16:58:50 236
原创 #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.按顺序合并两个链表注意链表=初始化以及返回的问题/** * Definition f
2016-04-26 20:54:19 245
原创 #leetcode#121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),
2016-04-26 20:25:57 174
原创 #leetcode#231. Power of Two
Given an integer, write a function to determine if it is a power of two.2的幂n&n-1,消掉最低位的1看是否为0class Solution {public: bool isPowerOfTwo(int n) { return ((n>0) && (n&(n-1))==0);
2016-04-26 19:56:43 191
原创 #leetcode#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 squares
2016-04-25 21:33:18 182
原创 #leetcode#326. Power of Three
326. Power of ThreeGiven an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?求3的幂思路1,迭代,不断除3,能否除尽思路2,
2016-04-25 20:57:45 227
原创 #leetcode#345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".只翻转元
2016-04-25 19:27:34 416
原创 #leetcode#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 ugly sinc
2016-04-25 18:31:08 184
原创 #leetcode#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?斐波那契数列,计算迭代f(n)=f(n-1)
2016-04-23 21:09:26 222
原创 #leetcode# 344 Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".建立两个指针,一个在头一个在尾交换两个指针的数值,之后一个++,一个--class Solution {public: s
2016-04-23 20:58:42 282
原创 #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.两个指针,注意细节,先判断head==NULL
2016-04-23 20:47:52 243
原创 #leetcode#191 Number of 1 Bits n&n-1的用处
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
2016-04-23 20:32:51 272
原创 #leetcode#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 defined betw
2016-04-23 20:08:23 191
原创 #leetcode#206. Reverse Linked List
单链表翻转(递归和迭代两种)迭代/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {
2016-04-19 23:09:35 178
原创 #leetcode#217 Contains Duplicate (map&排序)
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 element
2016-04-18 20:47:38 242
原创 #leetcode#169Majority 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 element
2016-04-15 22:06:08 204
原创 #leetcode#168 171 Excel Sheet Column Title 与 Excel Sheet Column Number
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 26进制转化
2016-04-15 21:22:11 208
原创 #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
2016-04-11 21:47:31 219
原创 #leetcode#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.1,排序后比较2
2016-04-07 21:50:15 175
原创 100. Same Tree
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 and the nodes have the same value.判断树是
2016-04-07 21:22:54 185
原创 #leetcode#237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2016-04-07 21:05:52 179
原创 #leetcode#283. Move Zeroes
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, given nums = [0, 1, 0, 3, 12], after calling you
2016-04-05 20:52:12 169
原创 #leetcode#226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1遍历方法/非遍历方法/** * Definition for a binary tree node. * struct TreeNod
2016-03-31 20:58:43 186
原创 #笔试相关#网易
网络协议:传输控制协议:TCP协议,面向连接,可靠的,基于字节流的传输层通信协议。传输层协议(OSI模型,物理层,数据链路层(点对点PTP协议,异步传输ATM,链路控制HDLC协议),网络层(IP协议,ARP地址解析协议,RARP,ICMP,IGMP),传输层(TCP,UDP),会话层,表示层,应用层)用户数据报协议:UDP,面向无连接,不可靠的传输层通信协议网际协议:IP协议,不可靠
2016-03-24 21:54:20 211
原创 #leetcode#104 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.遍历树,深度优先遍历/广度优先遍历深度优先遍
2016-03-20 17:42:39 256
原创 #leetcode#258 Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2016-03-20 16:49:38 184
原创 #leetcode#292 Nim Game
class Solution {public: bool canWinNim(int n) { return n % 4 != 0; }};寻找规律,简化代码return n & 0x3?????
2016-03-20 16:30:43 187
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人