- 博客(11)
- 收藏
- 关注
原创 LeetCode——爬梯子
分析计算时候发现就是 斐波那契数列 ;每次只能爬1步或2步,爬到第n层的方法要么是从第n-1层1步上来的,要不就是从n-2层2步上来的。递归:【超时】 int climbStairs(int n) { if (n < 0) return 0; if (n == 1 | n == 0) ...
2018-10-26 16:56:55 2768
原创 Tensorflow(fly)——基本用法
用变量实现一个简单的计数器#encoding UTF-8 #指定*.py的编码方式import tensorflow as tfstate = tf.Variable(0,name="counter")#使用tensorflow在默认的图中创建节点,这个节点是一个变量#one = tf.constant(1)#此处调用了tf的一个函数,用于创建常量new...
2018-10-08 19:32:17 194
原创 LeetCode——二进制求和
string addBinary(string a, string b) { int a_length = a.size(); int b_length = b.size(); if(a_length==0) return b; if(b_length==0) return a...
2018-10-07 16:34:07 261
原创 LeetCode——加一
vector<int> plusOne(vector<int>& digits) { int length = digits.size(); int focus = length - 1; digits[focus] += 1; while(digits[focus] == 1...
2018-10-07 15:45:54 135
原创 LeetCode——最后一个单词的长度
方法一:反向迭代器int lengthOfLastWord(string s) { int count = 0; for(auto item = s.rbegin(); item != s.rend(); item++) { if(*item == ' ') { ...
2018-10-07 14:57:16 172
原创 LeetCode——最大子序和
方法一【提交超时】——设计起点、终点、个数【O(n^3)】int maxSubArray(vector<int>& nums) { int max = nums[0]; for(int i = 0; i < nums.size(); ++i) { for (int j = i; j <...
2018-10-07 11:46:15 131
转载 大话数据结构——树
#include <string>#include <iostream>#include <vector>using namespace std;typedef enum {Link, Thread} PointerTag; /* Link==0表示指向左右孩子指针, */ /*...
2018-10-06 16:33:39 210
原创 LeetCode——反转整数
int reverse(int x) { int i=0; while (x!=0) { int n=i*10+x%10; x=x/10; if(n/10!=i)return 0; i=n; } return i;}
2018-10-01 15:25:37 93
原创 LeetCode——最长公共前缀
string longestCommonPrefix(vector<string>& strs) { int count = 0; string newstring = ""; if (strs.empty()) return ""; if(strs.size() == 1) ...
2018-10-01 14:56:14 96
原创 LeetCode——合并两个有序链表
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode...
2018-10-01 11:56:40 96
原创 LeetCode——报数
string countAndSay(int n) { string str = "1"; for (int i = 1; i < n; ++i) { string str_new{""}; for (int j = 0, count = 1; j < str.size()...
2018-10-01 10:54:15 525
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人