
LeetCode
biongbiongdou
这个作者很懒,什么都没留下…
展开
-
【LeetCode】 Two Sum
今天试了一下LeetCode,感觉有些用法之前没有接触过,以后要多练习。/** * Note: The returned array must be malloced, assume caller calls free(). */ int* twoSum(int* nums, int numsSize, int target) { int i,j; int* a=(int*)m...原创 2018-04-13 10:44:22 · 116 阅读 · 0 评论 -
【LeetCode】733. Flood Fill (C++)
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).Given a coordinate (sr, sc) representing the starting pixel (row and column...原创 2018-05-14 21:19:17 · 594 阅读 · 0 评论 -
【LeetCode】100. Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...原创 2018-05-14 20:47:43 · 164 阅读 · 0 评论 -
【LeetCode】690 Employee Importance(C++)
You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.For example, employee 1 is the leader of employee 2...原创 2018-05-14 20:23:30 · 239 阅读 · 0 评论 -
【LeetCode】226. Invert Binary Tree(C++)
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9to 4 / \ 7 2 / \ / \ 9 6 3 1这道题我是用递归求解的,代码如下:代码:(递归)/** * Definition for a binary tree node. * struct TreeN...原创 2018-05-07 22:02:01 · 209 阅读 · 0 评论 -
【LeetCode】104. Maximum Depth of Binary Tree(C++)
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.Note: A leaf is a node with no children.Ex...原创 2018-05-07 21:24:19 · 161 阅读 · 0 评论 -
【LeetCode】260. Single Number III(C++)
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,...原创 2018-05-06 11:51:17 · 274 阅读 · 0 评论 -
【LeetCode】137. Single Number II(C++)
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear runtime complexity. Cou...原创 2018-05-06 10:51:34 · 311 阅读 · 0 评论 -
【LeetCode】136 Single Number(C++)
Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ...原创 2018-05-06 10:10:20 · 218 阅读 · 0 评论 -
【LeetCode】Merge Two Binary Trees(C++)
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree. ...原创 2018-05-05 22:06:51 · 262 阅读 · 0 评论 -
【LeetCode】 Hamming Distance (C++)
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x, y < 231.Exa...原创 2018-05-05 21:33:10 · 240 阅读 · 0 评论 -
【LeetCode】Merge Two Sorted Lists(C++)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4 Output: 1->1...原创 2018-05-05 20:34:04 · 167 阅读 · 0 评论 -
【LeetCode】Valid Parentheses(C++)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brack...原创 2018-05-05 17:21:44 · 314 阅读 · 0 评论 -
【LeetCode】Two Sum (C++)
最近花了点时间了解了下C++,感觉与C还是有很多不同的。接下来坚持每天用C++写五道LeetCode。fighting!题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input w...原创 2018-05-05 16:50:00 · 135 阅读 · 0 评论 -
【LeetCode】695. Max Area of Island
题目:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are sur...原创 2018-05-11 16:38:28 · 172 阅读 · 0 评论 -
【LeetCode】108. Convert Sorted Array to Binary Search Tree(C++)
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 as a binary tree in which the depth of the t...原创 2018-05-14 22:11:06 · 257 阅读 · 0 评论