![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
obudunkey
低调做事
展开
-
Number of Digit One
题目:给定一个十进制正整数N,写下从1开始到N所有整数,然后数一下其中出现的所有1的个数思路:这道题在编程之美里有详细的解题过程,我这里复制一下,供大家参考假设N=abcde,如果要计算百位上出现1的次数,它将受到三个因素影响:百位上的数字,百位以下的数,和百位以上的数。(1)如果百位上的数字为0,百位上出现1的次数由更高位决定,比如12013,百位出现1的情况是:100-19转载 2017-03-01 19:11:32 · 411 阅读 · 0 评论 -
Convert BST to Greater Tree
题目描述:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in B原创 2017-04-27 19:50:13 · 299 阅读 · 0 评论 -
Repeated DNA Sequences
注:这种方法是在leetcode的讨论区看到的,所以说是转载,如有不妥,私信删除。题目描述:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful t转载 2017-05-17 21:06:21 · 316 阅读 · 0 评论 -
Diameter of Binary Tree
题目描述:Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path m原创 2017-04-26 11:17:03 · 233 阅读 · 0 评论 -
Delete Operation for Two Strings
题目描述:Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either string.Example 1:原创 2017-05-16 21:25:51 · 934 阅读 · 0 评论 -
Kill Process
题目描述:Given n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or more children processes. Thi原创 2017-05-16 21:08:12 · 706 阅读 · 0 评论 -
Binary Tree Tilt
题目描述:Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all r原创 2017-04-26 09:34:21 · 245 阅读 · 0 评论 -
Subarray Sum Equals K
问题描述:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2思路:记录原创 2017-05-02 19:52:05 · 825 阅读 · 0 评论 -
Game of Life
题目描述:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board原创 2017-05-01 11:24:38 · 349 阅读 · 0 评论 -
Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Ex原创 2017-05-01 10:31:32 · 594 阅读 · 0 评论 -
Brick Wall
题目描述:There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from the原创 2017-04-29 14:33:51 · 302 阅读 · 0 评论 -
Minesweeper
Let's play the minesweeper game (Wikipedia, online game)!You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an unrevealed empty squar原创 2017-04-28 17:06:02 · 228 阅读 · 0 评论 -
Unique Binary Search Trees II
题目描述:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown b转载 2017-02-27 13:03:45 · 237 阅读 · 0 评论 -
Find Largest Value in Each Tree Row
思路:变量level标识节点的深度(假设从0开始),vector res存放结果,Fun函数遍历整个树,当遍历到第i层时,如果res的长度小于i+1,则将该节点的数据加入res中,如果res长度大于等于i+1,则将该节点的数据与res[i]进行比较,如果大于res[i],则替换,这样保证res[i]最终存放的是i层最大的数void Fun(int level, vector& re原创 2017-02-26 19:46:33 · 368 阅读 · 0 评论 -
Find Bottom Left Tree Value
思路:建立一个有2个元素的vector,第一个元素存放叶子的深度,第二个叶子存放元素值 vector Fun(int level,TreeNode* node) { vector res(2,0); if (node==NULL) return res; if (node->left==NULL&&node->r原创 2017-02-26 18:20:49 · 295 阅读 · 0 评论 -
Base 7
题目要求:输入一个整数,将其7进制以字符串格式输出思路:比较简单,除k取余法 string convertToBase7(int num) { int tmp=abs(num); string ans=""; if (tmp==0) ans="0"; while(tmp) {原创 2017-02-24 23:28:28 · 330 阅读 · 0 评论 -
Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1原创 2017-03-02 00:02:01 · 455 阅读 · 0 评论 -
Sum of Square Numbers
题目描述:Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.Example 1:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5原创 2017-07-21 10:24:44 · 366 阅读 · 0 评论