
C++
文章平均质量分 60
张小小Angela
这个作者很懒,什么都没留下…
展开
-
LeetCode(55) Search Insert Position
题目描述Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.H原创 2015-09-23 21:00:23 · 656 阅读 · 0 评论 -
LeetCode (39) Ugly Number I II (丑数)
Ugly Number I 和 Ugly Number II原创 2015-09-22 21:12:32 · 1626 阅读 · 0 评论 -
LeetCode (35) Isomorphic Strings
题目描述Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another c原创 2015-05-07 15:03:57 · 1458 阅读 · 0 评论 -
LeetCode (29) Fraction to Recurring Decimal
题目描述Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For原创 2015-05-07 13:34:03 · 600 阅读 · 0 评论 -
LeetCode (32) Add Two Numbers (字符串)
题目描述You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a l原创 2015-05-07 14:26:59 · 484 阅读 · 0 评论 -
LeetCode (31) Divide two integers (不使用 *, /, mod 求两个数相除结果)
题目描述Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.对两个数 dividend 和 divisor,在不使用乘法、除法、取余操作求它们的相除结果,最直观的做法就是反复对 dividend - divisor 进行计数,直到差小原创 2015-05-07 14:13:23 · 618 阅读 · 0 评论 -
LeetCode (30) Palindrome Number (回文数字)
题目描述Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could negative integers be palindromes? (ie, -1) —— 负数不为回文If you are thinking of converting the integer to s原创 2015-05-07 13:51:45 · 1174 阅读 · 0 评论 -
LeetCode (34) Reverse Linked List
题目描述Reverse a singly linked list.例如: 1 -> 2 -> 3 -> 4 -> 5 -> 6 ==> 6 -> 5 -> 4 -> 3 -> 2 -> 1本题比较简单,使用两个指针,一个指针(p)表示前一个结点,另一个(l)表示当前结点。主要指针操作如下:ListNode* t = l -> next; // next of current nodel -> n原创 2015-05-07 14:57:48 · 2071 阅读 · 0 评论 -
LeetCode (33) 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.原创 2015-05-07 14:49:53 · 1020 阅读 · 0 评论 -
LeetCode (27) Linked List Cycle (判断cycle存在、寻找cycle入口节点)
判断cycle存在Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?本题要求判断给定链表中是否存在循环。并且题目要求不要使用extra space,因此,我们就不能保存每一个结点的value,在遍历的时候判断是否是循环。这道题可以通过原创 2015-04-28 14:36:06 · 1691 阅读 · 0 评论 -
Leetcode (28) Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3, 4].原创 2015-04-28 14:46:16 · 612 阅读 · 0 评论 -
OpenCV保存成XML(FileStorage)和CSV(重载<<运算符)文件
XML文件(使用FileStorage类)使用OpenCV时不仅要保存影像结果,往往也需要保存中间的矩阵结果,而OpenCV的imwrite函数只支持CV8U类型的数据(使用OpenCV保存其他类型Mat的时候,程序不会报错,但是无法生成结果文件),因此会给工作带来很多不便。OpenCV在2.0以后的版本中提供了FileStorage类,供用户直接使用,保存为XML/YAML文件。保存XML保存示例原创 2015-04-25 21:24:49 · 8647 阅读 · 7 评论 -
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-04-26 11:29:00 · 888 阅读 · 0 评论 -
LeetCode (24) 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原创 2015-04-26 10:59:17 · 12600 阅读 · 0 评论 -
LeetCode(42) 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.题目要求计算一棵二叉树的高度。本题最简单的解法是递归计算左右子树的高度,并在左原创 2015-09-23 10:59:19 · 574 阅读 · 0 评论 -
LeetCode(37) Contain Duplicates I II
共有两道与重复数字相关的题目,contain duplicates I 和 II。Contain Duplicates I题目描述Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least tw原创 2015-09-22 20:50:37 · 507 阅读 · 0 评论 -
LeetCode(52) Power of Two
题目描述Given an integer, write a function to determine if it is a power of two.判断一个数是否是2的指数。题目解答本题很简单可以通过位运算进行判断。首先如果一个数为负,则肯定不为2的指数,直接返回false;对于正数可以判断该数字二进制表达时1的个数,如果1的个数为只有一个则为2的指数,否则不为2的指数。class Soluti原创 2015-09-23 19:21:16 · 706 阅读 · 0 评论 -
LeetCode(41) Single Number I 和 II
题目描述Given an array of integers, every element appears twice except for one. Find that single one.如果一个给定数组中除了一个元素其他所有元素均出现了两次,这里让我们找到只出现了一次的元素。解题方法这里需要使用位运算来解决本题。我们知道异或运算有这样的结果a^a = 0,所以对数组中所有元素进行异或运算时,原创 2015-09-23 10:48:26 · 495 阅读 · 0 评论 -
LeetCode(47) Invert Binary Tree
题目描述Invert a binary tree. => 题目要求将二叉树的左右子树进行逆转。解题思路根据题目的要求可以进行一层一层的逆转,也就是交换结点的左右子树。将未处理的元素放入栈中,本题的关键在于对于元素的入栈顺序进行控制。/** * Definition for a binary tree node. * struct TreeNode { * int val; *原创 2015-09-23 18:11:22 · 463 阅读 · 0 评论 -
LeetCode(45) Simplify Path
题目描述Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c”本题要求对给定的Unix路径进行简化,关键点在于理解Unix路径的规则以及对一些边界条件要加以考虑。Unix路径规则:原创 2015-09-23 15:20:54 · 620 阅读 · 0 评论 -
LeetCode(51) Symmetric Tree
题目描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric:But the following is not:判断一棵二叉树是否对称。解题思路根据题目要求,可以认为是树的层序遍历的原创 2015-09-23 18:58:18 · 577 阅读 · 0 评论 -
LeetCode(46) Lowest Common Ancestor of a Binary (Search) Tree
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:原创 2015-09-23 16:11:22 · 546 阅读 · 0 评论 -
LeetCode(43) 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 only one digi原创 2015-09-23 11:22:10 · 637 阅读 · 0 评论 -
LeetCode(40) Median of Two Sorted Arrays (两排序数组中位数)
题目描述There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).题目要求寻找两个已排序数组的中位数解题代码本题我使用原创 2015-09-22 21:18:45 · 1851 阅读 · 0 评论 -
LeetCode (54) 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.Note: You may assume t原创 2015-09-23 19:42:19 · 645 阅读 · 0 评论 -
LeetCode(53) Climbing Stairs (剑指Offer->跳台阶、变态跳台阶)
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?本题对应了《剑指offe原创 2015-09-23 19:38:44 · 1864 阅读 · 0 评论 -
LeetCode(50) Binary Tree Inorder Traversal 中序遍历
题目描述Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3},return [1,3,2].解题思路之前在二叉树的先序遍历中已经介绍了二叉树遍历的思路了,这里直接上代码。递归解法/** * Definition for a bi原创 2015-09-23 18:50:53 · 486 阅读 · 0 评论 -
LeetCode(49) Populating Next Right Pointers in Each Node I II
Populating Next Right Pointers in Each Node I题目描述Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to i原创 2015-09-23 18:45:56 · 614 阅读 · 0 评论 -
LeetCode(38) 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原创 2015-09-22 20:57:00 · 476 阅读 · 0 评论 -
LeetCode(48) Binary Tree Preorder Traversal
题目描述Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, return [1,2,3].本题要求对二叉树进行先序遍历,所谓先序遍历:根-左-右,先遍历根结点,再遍历左子树,最后遍历右子树。递归求解二叉树的遍历最简单的原创 2015-09-23 18:24:14 · 572 阅读 · 0 评论 -
LeetCode (1) Two Sum
题目描述: The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and原创 2015-01-05 23:28:27 · 1357 阅读 · 0 评论 -
LeetCode (26) LRU Cache
题目描述Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if t原创 2015-04-26 11:50:56 · 965 阅读 · 2 评论 -
Leetcode (6) 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原创 2015-04-11 16:26:12 · 570 阅读 · 0 评论 -
LeetCode (17) Clone Graph
题目描述Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use # as a separator for each node,原创 2015-04-18 22:31:40 · 463 阅读 · 0 评论 -
LeetCode (15) Flatten Binary Tree to Linked List
题目描述Given a binary tree, flatten it to a linked list in-place.For example, Given The flattened tree should look like: 本题也是考察二叉树和指针操作的题目。题目要求将一棵二叉树拉平为一个链表 。链表通过树节点的右子树相连,且展开的顺序为原来树的前序遍历。实现思路:若节点n存原创 2015-04-18 22:16:43 · 894 阅读 · 1 评论 -
LeetCode (14) 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.使用字符串表示数字,对数字进行“加1”操作,返回结原创 2015-04-18 22:08:38 · 1070 阅读 · 0 评论 -
LeetCode (13) Pascal's Triangle (杨辉三角 )
题目描述Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return 从第三行开始,每行除了最左边和最右边两个数为1,其他数字都是上一行中相邻两个数字之和。根据上述规则可以写出下面的代码:class Solution {public: vecto原创 2015-04-18 22:01:22 · 1492 阅读 · 0 评论 -
LeetCode (12) Path Sum (二叉树路径和判断)
题目描述Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum原创 2015-04-18 21:58:17 · 969 阅读 · 0 评论 -
GDAL开源库在WIN8.1环境下的编译安装
最近因为实验需要,要在windows环境下利用GDAL进行开发,故尝试了一下编译GDAL。参考链接1:http://blog.youkuaiyun.com/liminlu0314/article/details/6937194参考链接2:http://malagis.com/win7-vs2010-gdal.html首先在GDAL官网上找到了下载链接,得到了最新的1.11.2版本的源代码,解压到D原创 2015-03-04 10:08:24 · 2904 阅读 · 0 评论 -
OpenCV的machine learning模块使用
opencv中提供的了较为完善的machine learning 模块,包含多种ml算法,极大了简化了实验过程。然而目前网上大部分的资料(包括官方文档)中关于ml模块的使用均是针对1.0风格的旧代码的,这对我们的学习造成了极大的困扰。本文将简单介绍一下如何使用opencv的ml模块进行实验。 首先,准备实验数据,我这里使用的是《模式分类》一书中第二章上机习题的部分数据,旨在进行一个简单的调用过原创 2014-12-15 19:32:18 · 13030 阅读 · 8 评论