Skip to content

Commit 552fd23

Browse files
committed
Array tag adds and three questions done
1 parent a86c141 commit 552fd23

File tree

11 files changed

+433
-0
lines changed

11 files changed

+433
-0
lines changed

Array/Array.Console/Array.Console.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Array.Console", "Array.Console\Array.Console.csproj", "{8172837B-6DA3-46AE-8E07-5F36A43011A7}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Array.Lib", "Array.Lib\Array.Lib.csproj", "{83D34E41-A053-4EB4-830E-6764DF3267AC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|Mixed Platforms = Debug|Mixed Platforms
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|Mixed Platforms = Release|Mixed Platforms
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Debug|Any CPU.ActiveCfg = Debug|x86
19+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
20+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Debug|Mixed Platforms.Build.0 = Debug|x86
21+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Debug|x86.ActiveCfg = Debug|x86
22+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Debug|x86.Build.0 = Debug|x86
23+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Release|Any CPU.ActiveCfg = Release|x86
24+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Release|Mixed Platforms.ActiveCfg = Release|x86
25+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Release|Mixed Platforms.Build.0 = Release|x86
26+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Release|x86.ActiveCfg = Release|x86
27+
{8172837B-6DA3-46AE-8E07-5F36A43011A7}.Release|x86.Build.0 = Release|x86
28+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
31+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
32+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Debug|x86.ActiveCfg = Debug|Any CPU
33+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
36+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
37+
{83D34E41-A053-4EB4-830E-6764DF3267AC}.Release|x86.ActiveCfg = Release|Any CPU
38+
EndGlobalSection
39+
GlobalSection(SolutionProperties) = preSolution
40+
HideSolutionNode = FALSE
41+
EndGlobalSection
42+
EndGlobal

Array/Array.Console/Array.Console.suo

18.5 KB
Binary file not shown.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{8172837B-6DA3-46AE-8E07-5F36A43011A7}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Array.Console</RootNamespace>
12+
<AssemblyName>Array.Console</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<PlatformTarget>x86</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
50+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
51+
Other similar extension points exist, see Microsoft.Common.targets.
52+
<Target Name="BeforeBuild">
53+
</Target>
54+
<Target Name="AfterBuild">
55+
</Target>
56+
-->
57+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Array.Console
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
13+
}
14+
}
15+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的常规信息通过以下
6+
// 特性集控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("Array.Console")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Array.Console")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 使此程序集中的类型
18+
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19+
// 则将该类型上的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("772bfdd4-30d5-41d4-b1a6-8d847e17f480")]
24+
25+
// 程序集的版本信息由下面四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 内部版本号
30+
// 修订号
31+
//
32+
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33+
// 方法是按如下所示使用“*”:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{83D34E41-A053-4EB4-830E-6764DF3267AC}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Array.Lib</RootNamespace>
12+
<AssemblyName>Array.Lib</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="PascalsTriangle.cs" />
44+
<Compile Include="PascalsTriangleII.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
<Compile Include="SearchInsertPosition.cs" />
47+
<Compile Include="ThirdMaximumNumber.cs" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
50+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
51+
Other similar extension points exist, see Microsoft.Common.targets.
52+
<Target Name="BeforeBuild">
53+
</Target>
54+
<Target Name="AfterBuild">
55+
</Target>
56+
-->
57+
</Project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* ==============================================================================
2+
* 功能描述:PascalsTriangle
3+
* 创 建 者:wack
4+
* 创建日期:2017/4/21 8:22:58
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
//Given numRows, generate the first numRows of Pascal’s triangle.
11+
12+
//For example, given numRows = 5,
13+
//Return
14+
15+
//[
16+
// [1],
17+
// [1,1],
18+
// [1,2,1],
19+
// [1,3,3,1],
20+
// [1,4,6,4,1]
21+
//]
22+
namespace Array.Lib
23+
{
24+
/// <summary>
25+
/// #118: Pascal’s Triangle
26+
/// </summary>
27+
public class PascalsTriangle
28+
{
29+
30+
public IList<IList<int>> Generate(int numRows)
31+
{
32+
IList<IList<int>> rtn = new List<IList<int>>();
33+
for (int i = 0; i < numRows; i++)
34+
{
35+
IList<int> ints = new List<int>();
36+
ints.Add(1);
37+
for (int j = 1; j < i; j++)
38+
{
39+
IList<int> intsPreRow = rtn[i - 1];
40+
ints.Add(intsPreRow[j - 1] + intsPreRow[j]);
41+
}
42+
if (i > 0)
43+
ints.Add(1);
44+
45+
rtn.Add(ints);
46+
}
47+
return rtn;
48+
}
49+
50+
}
51+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* ==============================================================================
2+
* 功能描述:PascalsTriangleII
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/21 8:24:50
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
//Given an index k, return the kth row of the Pascal’s triangle.
11+
12+
//For example, given k = 3,
13+
//Return [1,3,3,1].
14+
15+
//Note:
16+
//Could you optimize your algorithm to use only O(k) extra space?
17+
namespace Array.Lib
18+
{
19+
/// <summary>
20+
/// 119 : Pascal’s Triangle II
21+
/// </summary>
22+
public class PascalsTriangleII
23+
{
24+
public IList<int> GetRow(int rowIndex)
25+
{
26+
if (rowIndex < 0) return new List<int>();
27+
IList<int> levelList = new List<int>();
28+
for (int i = 0; i <= rowIndex; i++)
29+
{
30+
int k = levelList.Count;
31+
for (int j = k - 1; j >= 1; j--) //这个循环是最重要的一部分,巧妙的运用了Pascal三角的特点
32+
{
33+
levelList[j] = levelList[j - 1] + levelList[j];
34+
}
35+
levelList.Add(1);
36+
}
37+
return levelList;
38+
}
39+
40+
}
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的常规信息通过以下
6+
// 特性集控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("Array.Lib")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Array.Lib")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 使此程序集中的类型
18+
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19+
// 则将该类型上的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("dc0734d4-7ca7-40ce-9ce3-60d6ef2c10c1")]
24+
25+
// 程序集的版本信息由下面四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 内部版本号
30+
// 修订号
31+
//
32+
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33+
// 方法是按如下所示使用“*”:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* ==============================================================================
2+
* 功能描述:SearchInsertPosition
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/21 8:21:07
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
//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.
12+
13+
//You may assume no duplicates in the array.
14+
15+
//Here are few examples.
16+
//[1,3,5,6], 5 → 2
17+
//[1,3,5,6], 2 → 1
18+
//[1,3,5,6], 7 → 4
19+
//[1,3,5,6], 0 → 0
20+
21+
namespace Array.Lib
22+
{
23+
/// <summary>
24+
/// #35: Search Insert Position
25+
/// </summary>
26+
public class SearchInsertPosition
27+
{
28+
29+
public int SearchInsert(int[] nums, int target)
30+
{
31+
int lo = 0;
32+
int hi = nums.Length;
33+
while (lo < hi)
34+
{
35+
int mi = (lo + hi) >> 1;
36+
if (target <= nums[mi]) //目标值不大于中间位置的数时,hi变小
37+
hi = mi;
38+
else if (target > nums[mi]) //大于中间位置的值,lo加1
39+
lo = lo + 1;
40+
}
41+
return lo;
42+
}
43+
44+
45+
}
46+
}

0 commit comments

Comments
 (0)