编程
明引
一枚小小的程序猿......
展开
-
把数组排成最小的数
输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。 C++代码:class Solution {public: string minimunNumber(vector<int>& nums) { string ret; sort(n原创 2015-08-08 11:27:31 · 412 阅读 · 0 评论 -
leetcode:Shortest Palindrome
Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transfo原创 2015-08-29 20:02:47 · 432 阅读 · 0 评论 -
leetcode:Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key. The right原创 2015-08-04 15:51:40 · 422 阅读 · 0 评论 -
华为机试题:逛动物园
逛动物园Jack周日去动物园看“猩猩”,为了直达目的地,Jack想根据动物园地图计算从园区入口到“猩猩”馆的最短路径是多长?输入 5 4 0 7 3 10 15 7 0 5 13 12 3 5 0 5 10 10 13 5 0 11 15 12 10 11 0 输入中第一行第一个数为动物园展览馆总数n(包括0号馆),第二个数为“猩猩”馆的数字编号(入口编号为0号馆)。后面的输入是一个n原创 2015-08-31 16:47:46 · 1965 阅读 · 0 评论 -
树的广度优先遍历与深度优先遍历算法
1 树的广度优先搜索算法 广度优先搜索算法(Breadth First Search),又叫宽度优先搜索,或横向优先搜索。 是从根节点开始,沿着树的宽度遍历树的节点。如果所有节点均被访问,则算法中止。 如上图所示的二叉树,A 是第一个访问的,然后顺序是 B、C,然后再是 D、E、F、G。 那么,怎样才能来保证这个访问的顺序呢? 借助队列数据结构,由于队列是先进先出的顺序,因此可以先原创 2015-08-04 21:22:52 · 25518 阅读 · 2 评论 -
leetcode:Binary Tree Paths
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths.For example, given the following binary tree: All root-to-leaf paths are:[“1->2->5”, “1->3”]分析 深度搜索class Solution {public: v原创 2015-08-17 16:17:11 · 767 阅读 · 0 评论 -
leetcode:Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate原创 2015-08-18 09:43:03 · 585 阅读 · 0 评论 -
leetcode:Merge k Sorted Lists
Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析 The basic idea is really simple. We can merge first two lists and then push i原创 2015-08-19 11:12:13 · 512 阅读 · 0 评论 -
leetcode:Reverse Nodes in k-Group
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原创 2015-08-19 17:33:05 · 507 阅读 · 0 评论 -
leetcode:Substring with Concatenation of All Words
Substring with Concatenation of All Words You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation原创 2015-08-20 16:32:48 · 485 阅读 · 0 评论 -
leetcode:Combination Sum
Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unl原创 2015-08-21 16:39:15 · 567 阅读 · 0 评论 -
Ubantu16.04, Cuda9.1安装Tensorflow
1 准备安装Ubantu16.04, Cuda9.x, Cudnn7.0.5, 具体安装方法略2 安装参考github安装Tensorflow,在mkl安装的最后有如下命令行echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib' >> ~/.bashrc需要将上面的/usr/local/li...原创 2018-01-24 14:22:59 · 646 阅读 · 0 评论 -
正则表达式匹配
leetcode:Regular Expression Matching Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matc原创 2015-08-15 11:34:25 · 412 阅读 · 0 评论 -
leetcode:Number of Islands
## Number of Islands ## Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally原创 2015-08-03 16:23:23 · 360 阅读 · 0 评论 -
leetcode: 4Sum
分析: 先排序,然后左右夹逼 T(n)=O(n^3) 空间复杂的:T(n)=O(1) class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int target) { int size = nums.size(); vector<int> vec;原创 2015-07-31 17:36:25 · 372 阅读 · 0 评论 -
leetcode:Wildcard Matching
Wildcard MatchingImplement wildcard pattern matching with support for ‘?’ and ‘*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching原创 2015-08-22 15:53:19 · 674 阅读 · 0 评论 -
查找组成一个偶数最接近的两个素数
任意一个偶数(大于2)都可以由2个素数组成,组成偶数的2个素数有很多种情况,本题目要求输出组成指定偶数的两个素数差值最小的素数对 譬如:输入20 ,输出 7 13 C++代码: 最好时间复杂度:O(n^2) ,空间复杂度:O(1) #include<iostream>#include<vector>using namespace std;class Solution {public:原创 2015-08-10 16:33:08 · 554 阅读 · 0 评论 -
找出字符串中第一个只出现一次的字符
找出字符串中第一个只出现一次的字符 例如 输入:abcdab 输出:c C++代码: 时间复杂度:O(n),空间复杂度:O(1)#include<iostream>#include<vector>#include<string>#include<algorithm>#include<cctype>#include<unordered_map>using namespace st原创 2015-08-10 16:59:53 · 398 阅读 · 0 评论 -
放苹果
题目描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。 输入每个用例包含二个整数M和N。0<=m<=10,1<=n<=10。<=n<=10<=m<=10样例输入 7 3样例输出 8 方法一 深度搜索,时间复杂度O(mn),空间复杂度O(1)class Solution {public:原创 2015-08-11 20:00:50 · 451 阅读 · 0 评论 -
leetcode: Basic Calculator
leetcode: Basic CalculatorImplement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negat原创 2015-08-14 19:16:01 · 441 阅读 · 0 评论 -
Leecode:Convert Sorted Array to Binary Search Tree
描述 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 分析 二分法 代码// LeetCode, Convert Sorted Array to Binary Search Tree// 分治法,时间复杂度O(n),空间复杂度O(logn)c原创 2015-08-11 10:24:16 · 345 阅读 · 0 评论 -
leetcode:Basic Calculator II
Basic Calculator II Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer d原创 2015-08-26 09:39:40 · 592 阅读 · 0 评论 -
链表深拷贝
假设有如下一个链表:struct Node { int value ; struct Node *next ; struct Node *random ; } 其中,random指向该链表的任意一个节点或者NULL,请编程实现该链表的深拷贝。Node *deepCopy (Node *head)/* * 程序用来复制一个复杂链表 * 复杂链表表示原创 2015-07-31 10:15:13 · 5568 阅读 · 2 评论 -
合唱队
includeincludeincludeincludeincludeincludeinclude “math.h”using namespace std;class Solution { public: int minStudentOut(vector height){ int size =height.size(),ret=INT_MAX; vec原创 2015-07-30 20:45:19 · 337 阅读 · 0 评论 -
leetcode: Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list./** * Definition for singly-linked lis原创 2015-07-31 15:48:12 · 385 阅读 · 0 评论 -
树的两个节点的最低公共祖先
Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common a原创 2015-08-13 16:03:21 · 551 阅读 · 0 评论 -
源码升级cmake
参考博客: [ 源码升级cmake地址 ]原创 2018-06-20 11:45:15 · 351 阅读 · 0 评论