- 博客(80)
- 资源 (10)
- 收藏
- 关注
原创 26. Remove Duplicates from Sorted Array(重要!)
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2016-06-30 11:54:43 430
原创 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,1
2016-06-30 11:13:18 348
原创 66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.一个整数按位存储于一个int数组中,排列
2016-06-30 10:35:59 333
原创 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-06-29 17:01:41 321
原创 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-06-29 16:30:06 288
原创 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2016-06-29 16:14:51 336
原创 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-06-29 15:46:52 271
原创 236. Lowest Common Ancestor of a Binary Tree
跟这题相似 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最低公共祖先(难)Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definiti
2016-06-29 15:32:44 368
原创 网络字节序转换
主机有大端和小端网络字节序都是大端long htonl(long val){ return val > 8 & 0x0000FF00) | val >> 24;}int main(){ long val = 0x12345678; cout << hex << htonl(val) << endl; return 0;}结果78563412
2016-06-28 17:10:28 703
原创 229. Majority Element II (重要!)
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.若num与n1或n2相同,则将其对应的出现次数加1否则,若c1或c2为0,则将
2016-06-28 16:30:01 368
原创 326. Power of Three ,231. Power of Two ,
326. Power of Threelogn3=logn10log310class Solution {public: bool isPowerOfThree(int n) { double logRes = log10(n) / log10(3); if (logRes - (int)logRes == 0){ return true; } r
2016-06-28 15:09:10 313
原创 Contains Duplicate 包含重复
217. Contains DuplicateGiven 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 retur
2016-06-28 11:29:42 1020
原创 168. Excel Sheet Column Title Excel表列名 和 171. 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 class
2016-06-27 10:40:17 727
原创 242. Valid Anagram 有效的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.Note:You may ass
2016-06-27 10:10:20 318
原创 100. Same Tree 树是否相同
https://leetcode.com/problems/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 identica
2016-06-27 09:56:20 580
原创 237. Delete Node in a Linked List
https://leetcode.com/problems/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 l
2016-06-27 09:36:06 232
原创 Intersection of Two Arrays II两个数组交集(重要!)
https://leetcode.com/problems/intersection-of-two-arrays-ii/Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], retur
2016-06-26 23:21:28 2233
原创 349. Intersection of Two Arrays 两个数组交集
https://leetcode.com/problems/intersection-of-two-arrays/Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
2016-06-26 22:41:06 377
原创 179. Largest Number 排成最大的数字(重要!)
https://leetcode.com/problems/largest-number/Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest
2016-06-26 16:44:11 992
原创 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最低公共祖先(难)
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/[思路]如果如果p,q 比root小, 则LCA必定在左子树, 如果p,q比root大, 则LCA必定在右子树. 如果一大一小, 则root即为LCA./** * Definition for a binar
2016-06-25 23:13:44 352
原创 101. Symmetric Tree 对称树 (难点!)
https://leetcode.com/problems/symmetric-tree/Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] i
2016-06-25 19:14:34 514
原创 226. Invert Binary Tree 翻转二叉树
https://leetcode.com/problems/invert-binary-tree/invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Defin
2016-06-25 16:36:38 296
原创 110. Balanced Binary Tree 平衡二叉树(重点!!)
https://leetcode.com/problems/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 whic
2016-06-25 15:46:03 472
原创 111. Minimum Depth of Binary Tree 二叉树的最小深度
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.注意 : 12 这样的二
2016-06-25 15:22:26 321
原创 23. Merge k Sorted Lists 合并K个有序链表
https://leetcode.com/problems/merge-k-sorted-lists//** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next
2016-06-25 11:46:41 537
原创 204. Count Primes 统计素数
https://leetcode.com/problems/count-primes/Description:Count the number of prime numbers less than a non-negative number, n.筛选法class Solution {public: int countPrimes(int n)
2016-06-25 11:13:28 354
原创 264. Ugly Number II
https://leetcode.com/problems/ugly-number-ii/Write a program to find the n-th ugly number.这次又犯了一次错误:注意三个if判断,不能用else if。因为有可能有多个if同时满足!class Solution {public: int nthUglyN
2016-06-25 10:26:10 248
原创 263. Ugly Number 丑数
https://leetcode.com/problems/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. Fo
2016-06-25 09:43:07 243
原创 202. Happy Number
https://leetcode.com/problems/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
2016-06-24 22:50:12 905
原创 Add Digits
https://leetcode.com/problems/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,
2016-06-24 22:17:18 410
原创 Nim游戏 Nim Game
https://leetcode.com/problems/nim-game/博弈论中极为经典的尼姆游戏。有总数为n的石头,每个人可以拿1~m个石头,两个人交替拿,拿到最后一个的人获胜。究竟是先手有利,还是后手有利?1个石子,先手全部拿走; 2个石子,先手全部拿走; 3个石子,先手全部拿走; 4个石子,后手面对的是先手的第1,2,3情况,后手必胜; 5个石子,先手拿走1个让后手面对第4种情况
2016-06-24 22:02:10 644
原创 移出元素 Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.
2016-06-23 15:04:33 945
原创 移动零 Move Zeroes
https://leetcode.com/problems/move-zeroes/思路跟快排的第二种partition函数类似class Solution {public: void moveZeroes(vector<int>& nums) { int len = nums.size(); if (len <= 1){ retur
2016-06-23 14:43:12 201
原创 逆转字符串中的元音字母 Reverse Vowels of a String
https://leetcode.com/problems/reverse-vowels-of-a-string/class Solution {public: string reverseVowels(string s) { int len = s.size(); if (len <= 1){ return s; }
2016-06-23 11:51:28 380
原创 逆转字符串Reverse String
https://leetcode.com/problems/reverse-string/class Solution {public: string reverseString(string s) { int len = s.size(); if (len <= 1){ return s; } int
2016-06-23 11:20:05 282
原创 N-皇后 N-Queens
https://leetcode.com/problems/n-queens/class Solution {public: vector<vector<string>> solveNQueens(int n) { if (n <= 0){ return res; } vector<int> sol(n);
2016-06-23 11:09:43 261
原创 有效数独 Valid Sudoku
https://leetcode.com/problems/valid-sudoku/class Solution {public: bool isValidSudoku(vector<vector<char> >& board) { int row[9]={0}; int col[9]={0}; int box[9]={0};
2016-06-23 10:25:25 471
转载 ping和traceroute工作原理
ping命令工作原理ping命令主要是用于检测网络的连通性。Ping命令发送一个ICMP请求报文给目的IP,然后目的IP回复一个ICMP报文。原理:网络上的机器都有唯一确定的IP地址,我们给目标IP地址发送一个数据包,对方就要返回一个同样大小的数据包,根据返回的数据包我们可以确定目标主机的存在,可以初步判断目标主机的操作系统等。因为ping命令是使用ICMP协议,所以没有端口号,但
2016-06-21 22:31:58 1619
原创 最长回文子串、最长回文子序列、回文子序列个数
最长回文子串已经整理过:http://blog.csdn.net/gao1440156051/article/details/517281031.最长回文子序列要求:给定字符串,求它的最长回文子序列长度。回文子序列反转字符顺序后仍然与原序列相同。例如字符串abcdfcba中,最长回文子序列长度为7,abcdcba或abcfcba。思路:动态规划思想
2016-06-21 17:11:59 533
原创 最长回文子串 Longest Palindromic Substring
https://leetcode.com/problems/longest-palindromic-substring/Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one
2016-06-21 16:16:38 309
Win7平台VS2010安装Visual Assist X
2015-03-20
合工大操作系统课程设计:基于内存的文件系统
2013-07-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人