- 博客(54)
- 资源 (1)
- 收藏
- 关注
原创 202. Happy Number
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 squares of i
2017-01-29 10:16:22 146
原创 171. Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26
2017-01-29 09:18:38 263
原创 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB class Solution { publ
2017-01-27 10:56:39 153
原创 167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers suc
2017-01-27 10:08:30 160
原创 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ c1
2017-01-27 09:26:15 148
原创 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \ 2 3 \ 5All root-to-leaf paths are:[“1->2->5”, “1->3”]/** * Definition for a binary tr
2017-01-25 15:13:37 164
原创 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t
2017-01-25 14:41:55 140
原创 326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up: Could you do it without using any loop / recursion?class Solution { public: bool isPowerOfThree(int n) {
2017-01-23 22:30:47 140
原创 231. Power of Two
Given an integer, write a function to determine if it is a power of two.class Solution { public: bool isPowerOfTwo(int n) { int s = 0; if(n < 1) return false; for(int i = 0;
2017-01-23 21:51:53 134
原创 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For e
2017-01-23 20:31:05 125
原创 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run in li
2017-01-23 14:55:38 206
原创 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is
2017-01-22 21:01:09 141
原创 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume the s
2017-01-22 20:42:49 190
原创 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 /** * Definition for a binary tree node. * struct TreeNode { *
2017-01-22 20:21:49 139
原创 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the
2017-01-22 19:58:30 134
原创 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].Note: Recursive solution is trivial,
2017-01-21 21:16:58 158
原创 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space? 思路参考:http://b
2017-01-21 20:47:21 173
原创 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode { * int val; * ListN
2017-01-21 19:42:49 151
原创 137. Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.一道挺有意思的题目。class Solution { public: int singleNumber(vector<int>& nums)
2017-01-20 22:28:54 166
原创 0.初次使用curl
windows10 + vs2010使用curl(command URL)库 curl库的编译可以参考:http://blog.csdn.net/neverup_/article/details/21961017 openssl解压要使用管理员权限解压(不会请百度),不然会出现符号链接错误。 具体的使用可以看curl官网提供的API和example: https://curl.haxx.se/
2017-01-20 22:19:59 339
原创 136. Single Number
Given an 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 extra me
2017-01-20 11:11:45 163
原创 125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is not a palin
2017-01-17 23:59:24 195
原创 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and
2017-01-17 23:37:25 164
原创 121. Best Time to Buy and Sell Stock
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 stock), desi
2017-01-17 23:31:07 167
原创 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].class Solution { public: vector<int> getRow(int rowIndex) { vector<int> ans;
2017-01-17 23:09:03 548
原创 118. Pascal's Triangle
Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] 思路:动态规划,初始值:F[0,0]=1,F[1,0]=1,F[1,1]=1 F[i]
2017-01-16 23:27:06 509
原创 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum = 2
2017-01-16 22:46:50 280
原创 111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tree node.
2017-01-15 23:55:35 206
原创 107. Binary Tree Level Order Traversal II
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,null,15,7],
2017-01-15 23:00:07 178
原创 103. 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 between).For example: Given binary tree
2017-01-15 22:46:09 164
原创 104. Maximum Depth of Binary Tree
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./** * Definition for a binary tree node.
2017-01-10 21:54:49 242
原创 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20
2017-01-10 21:39:06 157
原创 1013. Battle Over Cities (25)
It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need
2017-01-10 20:56:38 178
原创 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3
2017-01-08 23:35:55 171
原创 100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.这个花了3ms/** * Defin
2017-01-08 23:22:54 181
原创 96. Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s. 思路:动态规划。当n=7的时候,1为根结点,左边0个节点,右边6个节点和7为根结点对称,这种
2017-01-07 23:45:32 274
原创 88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.class Solution { public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { int a
2017-01-07 22:38:29 185
原创 1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the le
2017-01-05 16:33:23 211
原创 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the ch
2017-01-04 12:50:37 185
原创 1090. Highest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the ch
2017-01-04 12:43:27 196
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人