![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++OJ
文章平均质量分 51
WhiteJunior
这个作者很懒,什么都没留下…
展开
-
628. Maximum Product of Three Numbers
1,题目要求 Given an integer array, find three numbers whose product is maximum and output the maximum product. 需要注意的是,给定的数字中也有负数的存在,因此需要单独进行判断。 2,题目思路: 题目的要求是求出三个数的最大的成乘积,因此想到的办法便是对其进行排序,然后直接取最大的三个数...原创 2018-03-07 13:38:04 · 175 阅读 · 0 评论 -
744. Find Smallest Letter Greater Than Target
1,题目要求 Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.Lett...原创 2018-03-08 18:44:27 · 249 阅读 · 0 评论 -
350. Intersection of Two Arrays II
1,题目要求 Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. 求两个数组的交集。 2,题目思路 利用Hash表即可达到条件。需要注意的是,定义Hash表用到一个特殊的方...原创 2018-03-09 13:48:58 · 123 阅读 · 0 评论 -
541. Reverse String II
1,题目要求 Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all...原创 2018-03-15 22:42:27 · 124 阅读 · 0 评论 -
551. Student Attendance Record I
1,题目要求 You are given a string representing an attendance record for a student. The record only contains the following three characters: ‘A’ : Absent. ‘L’ : Late. ‘P’ : Present. A student could be...原创 2018-03-10 00:22:21 · 117 阅读 · 0 评论 -
746. Min Cost Climbing Stairs
1,题目要求 On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the...原创 2018-03-16 20:30:46 · 136 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock
1,题目要求 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 s...原创 2018-03-17 14:30:35 · 144 阅读 · 0 评论 -
409. Longest Palindrome
1,题目要求: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is ...原创 2018-03-04 14:21:51 · 158 阅读 · 0 评论 -
108. Convert Sorted Array to Binary Search Tree
1,题目要求 给定一个升序排列的数组,将其转化为一个高度平衡的二叉搜索树。 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined ...原创 2018-03-11 19:49:50 · 127 阅读 · 0 评论 -
674. Longest Continuous Increasing Subsequence
1,题目要求 Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray). 找到一个连续的最长递增子序列。 2,题目思路 还是利用了动态规划的基本思想。动态去依次寻找最长的递增子序列。设置一个count变量来记录每次满足递增条件的...原创 2018-03-18 11:01:28 · 167 阅读 · 0 评论 -
543. Diameter of Binary Tree
1,题目要求 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 may ...原创 2018-03-05 11:58:03 · 237 阅读 · 0 评论 -
796. Rotate String
1,题目要求 We are given two strings, A and B.A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, if A = ‘abcde’, then it will be ‘bcdea’ a...原创 2018-03-12 16:11:36 · 714 阅读 · 0 评论 -
415. Add Strings
1,题目要求 Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100. Both num1 and num2 contains only d...原创 2018-03-22 14:46:19 · 138 阅读 · 0 评论 -
268. Missing Number
1,题目要求: Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. 也就是给n个数字,判断少了哪个数字。要求用线性的时间来进行探查,并利用有限的额外空间。 2,题目思路: 一开始想直接利用vector的排序函...原创 2018-03-05 19:28:07 · 137 阅读 · 0 评论 -
107. Binary Tree Level Order Traversal II
1,题目要求 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,...原创 2018-03-19 14:33:25 · 132 阅读 · 0 评论 -
784. Letter Case Permutation
1,题目要求 一种对字母的大小写形式的一种遍历,对数字不做处理。 2,题目思路 题目看起来不难,可是仔细思考发现一定要用到递归思想,否则穷举法根本不能实现。 因此,设计递归形式就非常关键了。 递归在设计时,个人觉得重要的是返回出口在哪里,以及每次结果的产生的记录。 因此,主题函数如下: 3,程序源码class Solution {public: vector&l...原创 2018-03-13 14:51:11 · 242 阅读 · 0 评论 -
401. Binary Watch
1,题目要求 A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant...原创 2018-03-06 15:08:36 · 228 阅读 · 0 评论 -
202. Happy Number
1,题目要求 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 s...原创 2018-03-23 19:45:26 · 219 阅读 · 0 评论 -
747. Largest Number At Least Twice of Others
1,题目要求 In a given integer array nums, there is always exactly one largest element.Find whether the largest element in the array is at least twice as much as every other number in the array.If it ...原创 2018-03-20 10:15:30 · 320 阅读 · 0 评论 -
504. Base 7
1,题目要求 将一个数转化为7进制的数 注意转化为一个字符串。 2,题目思路 对于负数,要进行记录并将其转化为正数再进行操作。 跟在十进制时获得每一位的数字时的方法相同,只不过将10变为7即可。 3,程序源码class Solution {public: string convertToBase7(int num) { if(num < 0)...原创 2018-03-14 15:32:28 · 187 阅读 · 0 评论 -
720. Longest Word in Dictionary
1,题目要求 Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there is more than one po...原创 2018-03-24 15:33:58 · 218 阅读 · 0 评论 -
70. Climbing Stairs
1,题目要求 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? 对于n阶的楼梯,一次可以爬一阶或者两阶楼梯,...原创 2018-03-25 12:52:21 · 203 阅读 · 0 评论 -
671. Second Minimum Node In a Binary Tree
1,题目要求 Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this n...原创 2018-03-21 10:50:25 · 154 阅读 · 0 评论 -
326. Power of Three
1,题目要求 Given an integer, write a function to determine if it is a power of three. 即给定一个数字,判断其是否是3的幂次。返回true false。不要使用循环或者迭代。2,题目思路 无法使用循环或者迭代,则必须要利用幂次的数学原理来进行求解。 参考后,一共两种思路办法,而且这两种方法应该都具有通用性。...原创 2018-03-30 20:53:31 · 257 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
1,题目要求 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2-...原创 2018-04-08 10:32:44 · 121 阅读 · 0 评论 -
231. Power of Two
1,题目要求 Given an integer, write a function to determine if it is a power of two. 即判断一个数是不是2的幂次。2,跟前面求是否是3的幂次类似,可以直接套用那两种思想。 同时,可以用一种新的方式,适用于2的幂次的方法: 首先,2的幂次的二进制形式都是“100..0”的形式,因此,如果n是2的幂次,则其与n-1进...原创 2018-03-31 14:46:50 · 235 阅读 · 0 评论 -
594. Longest Harmonious Subsequence
1,题目要求 We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its lon...原创 2018-03-26 13:49:20 · 134 阅读 · 0 评论 -
804. Unique Morse Code Words
1,题目要求 International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” maps to “.-“, “b” maps to “-…”, “c” maps to “-.-.”, and so on. ...原创 2018-04-01 12:25:57 · 161 阅读 · 0 评论 -
572. Subtree of Another Tree
1,题目要求 判断一棵树是否是另一棵树的子树。 需要注意的是,这里的子树不是含有就是子树,要求原树中的子树部分不能有其他节点,就像example2中所说的那样。2,题目思路 一开始,想象直接对s进行中序遍历,如果有节点的值和t的节点的值相同,就直接判断该s节点的左右节点的值是否和t左右节点的值相同。另外一种思路就是将s和t完全中序遍历并存储在向量中,然后做一个相同判断。 上述两...原创 2018-04-09 11:00:32 · 158 阅读 · 0 评论 -
811. Subdomain Visit Count
1,题目要求 英文叙述非常的不明确,直接截图来阐释。前面的数字可以看做出现的个数。问题要求统计各个域名出现的次数。2,题目思路 对于统计数目类型的问题,在python中的话首先想到的就是字典,而在C++中,想到的便是和字典类似的map容器。这种容器在前面也有介绍过,其他的博客对map和unordered_map也有很详细的介绍,这里便不再赘述。 另外一点,便是如何得到不同长度的域名。...原创 2018-04-02 12:29:52 · 1333 阅读 · 0 评论 -
257. Binary Tree Paths
1,题目要求 Given a binary tree, return all root-to-leaf paths. 2,题目思路 依然是利用递归的方法,对整棵树进行遍历,每当找到左右孩子节点都为空的节点时,便将这一条路径得到字符串加入到vector中;否则,就对左右子树分别进行路径的查询。 树的递归最好写一个递归函数来进行操作。3,程序源码/** * Definitio...原创 2018-03-27 14:16:03 · 136 阅读 · 0 评论 -
66. Plus One
1,题目要求 Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The ...原创 2018-04-15 11:07:20 · 193 阅读 · 0 评论 -
437. Path Sum III
1,题目要求 You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, bu...原创 2018-04-10 10:39:44 · 147 阅读 · 0 评论 -
806. Number of Lines To Write String
1,题目要求 又是一道新的题目,又是一大堆意义不明的要求,因为已经没有新的题目了么? 题目的意思,width为26个元素,每个代表a-z的长度。对应字符串s,总长度是可以得到的,而一行最多可以放100。问一共有几行,而且最后一行长度为多少?其中一个字母如果在这一行放不下,那么只能新开辟一行来进行存放。2,题目思路 很简单的一道题目,就是简单的字母-数组对应,然后做一个累加判断即可。因...原创 2018-04-03 10:24:56 · 469 阅读 · 0 评论 -
263. Ugly Number
1,题目要求 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. For example, 6, 8 are ugly while 14 is not ugly ...原创 2018-04-16 11:10:14 · 263 阅读 · 0 评论 -
405. Convert a Number to Hexadecimal
1,题目要求 将十进制的数字转换为十六进制的形式,并且要可以对负数进行转换。 2,题目思路 如果仅仅是对十进制的数字转换为十六进制,其实还是不难的,关键在于对负数应该如何去处理。 在这里面,负数是转化为补码的形式来进行运算的。 在参考的算法后,得到了如下的实现思路: 首先,定义一个字符串,用来获取相应十进制->十六进制的相关字符串。当然,也可以用字符相加减来获得,不过还需要将...原创 2018-03-28 13:38:44 · 316 阅读 · 0 评论 -
35. Search Insert Position
1,题目要求 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. 对一个已经进行排序的数组中寻找目标值,如果找到了就返回对应的inde...原创 2018-04-11 11:02:42 · 178 阅读 · 0 评论 -
27. Remove Element
1,题目要求 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 by modifying the input array...原创 2018-04-04 10:29:47 · 94 阅读 · 0 评论 -
482. License Key Formatting
1,题目要求 You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by N dashes.Given a number K, we would wa...原创 2018-04-17 13:39:05 · 139 阅读 · 0 评论 -
191. Number of 1 Bits
1,题目要求 Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation; ...原创 2018-04-05 10:54:58 · 96 阅读 · 0 评论