原创 206. Reverse Linked List

Reverse a singly linked list. /** * Definition for singly-linked list. * struct ListNode { * int val; *

原创 C++數據結構---二叉樹(樹的節點創建)

二叉樹是一種比較重要的數據結構,圖就是根據二叉樹來編寫的。 代碼如下: #pragma once #ifndef BINNODE__HH #define BINNODE__HH #include<iostream> #incl

原创 234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) spac

原创 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. Suppos

原创 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

原创 202. Happy Number

Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process

原创 19. Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list:

原创 4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays.

原创 61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5-

原创 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? /*

原创 263. Ugly Number

Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime fa

原创 C++實現LeetCode(三個數的和最接近目標數)

Leetcode:16題: Given an array S of n integers, find three integers in S such that the sum is closest to a given num

原创 C++數據結構---鏈表(鏈表節點創建)

本文是爲了以下創建鏈表更加方便,而編寫的C++頭文件,作用是創建一個節點類,此處不採用class,而用struct。 Struct和Class的區別在於: 二者的訪問權限不同!!!! 前者:訪問權限是public 後者:訪問

原创 C++數據結構---鏈表(鏈表創建)

鏈表 是比較重要的一種數據結構,它的有點在於:插入和刪除操作。 與vector不同,list插入和刪除不需要移動其餘元素,而vector在中間插入時,需要將後面的元素依次向後移動,時間複雜度與待移動的元素有關,可見,元素越多,消

原创 264. Ugly Number II

Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2,