刷题
Tong_hdj
这个作者很懒,什么都没留下…
展开
-
283. Move Zeroes--LeetCode Record
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your原创 2016-07-10 00:18:20 · 208 阅读 · 0 评论 -
338. Counting Bits--LeetCode Record
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array. Example: For num =原创 2016-07-05 01:26:34 · 216 阅读 · 0 评论 -
292. Nim Game--LeetCode Record
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原创 2016-07-06 01:51:48 · 164 阅读 · 0 评论 -
202. Happy Number --LeetCode Record
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 square原创 2016-07-17 01:13:46 · 196 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree --LeetCode Record
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwe原创 2016-07-17 01:31:01 · 205 阅读 · 0 评论 -
263. Ugly Number--LeetCode Record
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 since原创 2016-07-17 10:53:16 · 235 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List--LeetCode Record
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->3. func deleteDuplic原创 2016-07-17 11:12:09 · 205 阅读 · 0 评论 -
371. Sum of Two Integers--LeetCode Record
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. 抓住了一些运算符的特性,题目不难class Solution { func getSum(a: Int, _原创 2016-07-07 00:58:46 · 216 阅读 · 0 评论 -
258. Add Digits--LeetCode Record
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only原创 2016-07-08 01:53:54 · 156 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree--LeetCode Record
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原创 2016-07-08 02:11:51 · 228 阅读 · 0 评论 -
121. Best Time to Buy and Sell Stock--LeetCode Record
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)原创 2016-07-18 22:18:21 · 217 阅读 · 0 评论 -
226. Invert Binary Tree--LeetCode Record
/** * Definition for a binary tree node. * public class TreeNode { * public var val: Int * public var left: TreeNode? * public var right: TreeNode? * public init(_ val: Int) { *原创 2016-07-08 23:05:13 · 299 阅读 · 0 评论 -
344. Reverse String--LeetCode Record
Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”. class Solution { func reverseString(s: String) -> String {原创 2016-07-04 01:56:43 · 198 阅读 · 0 评论 -
191. Number of 1 Bits--LeetCode Record
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 0000000原创 2016-07-14 16:38:17 · 218 阅读 · 0 评论 -
231. Power of Two--LeetCode Record
Given an integer, write a function to determine if it is a power of two. 水到家了! func isPowerOfTwo(n: Int) -> Bool { return ( n > 0 && 1073741824 % n == 0); }原创 2016-07-14 16:11:45 · 180 阅读 · 0 评论 -
349. Intersection of Two Arrays--LeetCode Record
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique. Th原创 2016-07-10 02:02:20 · 218 阅读 · 0 评论 -
237. Delete Node in a Linked List--LeetCode Record
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 valu原创 2016-07-10 13:11:43 · 194 阅读 · 0 评论 -
100. Same Tree--LeetCode Record
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. /** * Defin原创 2016-07-10 21:24:16 · 208 阅读 · 0 评论 -
242. Valid Anagram--LeetCode Record
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. class Solution {原创 2016-07-11 16:01:52 · 188 阅读 · 0 评论 -
171. Excel Sheet Column Number--LeetCode Record
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 A原创 2016-07-11 17:05:37 · 199 阅读 · 0 评论 -
169. Majority Element--LeetCode Record
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element a原创 2016-07-12 23:38:58 · 223 阅读 · 0 评论 -
217. Contains Duplicate--LeetCode Record
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原创 2016-07-13 00:33:43 · 170 阅读 · 0 评论 -
13. Roman to Integer--LeetCode Record
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. let record:[Character:Int] = ["M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V":原创 2016-07-14 00:26:49 · 195 阅读 · 0 评论 -
206. Reverse Linked List--LeetCode Record
Reverse a singly linked list. /** * Definition for singly-linked list. * public class ListNode { * public var val: Int * public var next: ListNode? * public init(_ val: Int) { *原创 2016-07-14 00:55:22 · 174 阅读 · 0 评论 -
350. Intersection of Two Arrays II--LeetCode Record
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as m原创 2016-07-14 15:09:15 · 151 阅读 · 0 评论 -
326. Power of Three--LeetCode Record
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? 水! func isPowerOfThree(n: Int) -> Bool { //原创 2016-07-14 15:55:47 · 150 阅读 · 0 评论 -
141. Linked List Cycle--LeetCode Record
Given a linked list, determine if it has a cycle in it. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL)原创 2016-07-20 09:31:28 · 186 阅读 · 0 评论