using System;

public class Seven Star Lottery. 751 Lottery. The winning number is 1257893.619858 complete the task.
{
public static void Main()
{
//程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
Console.WriteLine("Seven Star Lottery. 751 Lottery. The winning number is 1257893.619858 complete the task. JSRUN - from C# ");
}
}
2785655466(前端大神) - 2020-01-16 0 人
751.csh
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class HelloWorld
{
    public static void Main()
    {
       var l1 = CommonHelper.GenerateList(10,10);
       var l2 = LeetCode.DuplicateSimpleList(l1);

       Console.WriteLine(CommonHelper.PrintList(l1));
       Console.WriteLine(CommonHelper.PrintList(l2));
    }
}

#region LeetCode
public class LeetCodeHelper
    {
        public static void Rotate(int[] nums, int k)
        {
            if (nums == null || nums.Length == 0 || k < 0)
            {
                return;
            }

            int length = nums.Length;
            int[] ret = new int[length];
            int dividePoint = length - (k % length);
            int newIndex = 0;

            for (int i = dividePoint; i < length; i++)
            {
                ret[newIndex++] = nums[i];
            }

            for (int i = 0; i < dividePoint; i++)
            {
                ret[newIndex++] = nums[i];
            }

            nums = ret;
        }

        public static int Partion(List<int> input, int left, int right)
        {
            int pivot = input[left];
            int i = left + 1;
            int j = right;

            while (i < j)
            {
                while (i < j && input[right] >= pivot)
                {
                    j--;
                }

                while (i < j && input[left] <= pivot)
                {
                    i++;
                }

                if (i <= j)
                {
                    int temp = input[i];
                    input[i] = input[j];
                    input[j] = temp;
                }
            }

            input[left] = input[j];
            input[j] = pivot;

            return left;
        }

        public static void TestTreeNode()
        {
            var tn1 = new TreeNode(1);
            var tn2 = new TreeNode(2);
            var tn3 = new TreeNode(3);
            var tn4 = new TreeNode(4);
            var tn5 = new TreeNode(5);
            var tn6 = new TreeNode(6);
            var tn7 = new TreeNode(7);
            var tn8 = new TreeNode(8);

            tn1.Left = tn2;
            tn1.Right = tn3;

            tn2.Left = tn4;
            tn2.Right = tn5;

            tn3.Left = tn6;
            tn3.Right = tn7;

            tn4.Left = tn8;

            Console.WriteLine(CommonHelper.PrintTreeNode(tn1));
        }

        public static void SelectionSort(List<int> input)
        {
            if (input == null)
            {
                return;
            }

            var length = input.Count;

            for (int i = 0; i < length; i++)
            {
                int minIndex = i;
                for (int j = i + 1; j < length; j++)
                {
                    if (input[j] < input[minIndex])
                    {
                        minIndex = j;
                    }
                }

                var temp = input[i];
                input[i] = input[minIndex];
                input[minIndex] = temp;
            }
        }

        public static void InsertionSortV1(List<int> input)
        {
            for (int i = 0; i < input.Count; i++)
            {
                for (int j = i; j > 0; j--)
                {
                    if (input[j] < input[j - 1])
                    {
                        int temp = input[j];
                        input[j] = input[j - 1];
                        input[j - 1] = temp;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }

        public static void InsertionSortV2(List<int> input)
        {
            for (int i = 0; i < input.Count; i++)
            {
                int current = input[i];
                int j = i;
                for (; j > 0; j--)
                {
                    if (current < input[j - 1])
                    {
                        input[j] = input[j - 1];
                    }
                    else
                    {
                        break;
                    }
                }
                input[j] = current;
            }
        }

        public static void BobbleSort(List<int> input)
        {
            for (int i = 0; i < input.Count - 1; i++)
            {
                for (int j = 0; j < input.Count - i - 1; j++)
                {
                    if (input[j] > input[j + 1])
                    {
                        int temp = input[j];
                        input[j] = input[j + 1];
                        input[j + 1] = temp;
                    }
                }
            }
        }

        public static void QuickSort(List<int> input, int left, int right)
        {
            if (left < right)
            {
                var pivot = Partion(input, left, right);

                QuickSort(input, left, pivot - 1);
                QuickSort(input, pivot + 1, right);
            }
        }

        public static void MergeSort(List<int> input)
        {
            MergeSortHelper(input, 0, input.Count - 1);
        }

        private static void MergeSortHelper(List<int> input, int l, int r)
        {
            if (l >= r)
            {
                Console.WriteLine(string.Format("递归终止 l - > {0} r -> {1}", l, r));
                return;
            }

            int mid = (l + r) / 2;

            Console.WriteLine(string.Format("进入递归 l -> {0} r -> {1} mid -> {2}", l, r, mid));

            MergeSortHelper(input, l, mid);
            MergeSortHelper(input, mid + 1, r);

            Merge(input, l, mid, r);
        }

        private static void Merge(List<int> input, int l, int mid, int r)
        {
            Console.WriteLine(string.Format("进入归并 l -> {0} r -> {1} mid -> {2}", l, r, mid));

            List<int> temp = new List<int>();

            for (int j = 0; j < r - l + 1; j++)
            {
                temp.Add(-1);
            }

            int i = 0;
            int p1 = l;
            int p2 = mid + 1;

            while (p1 <= mid && p2 <= r)
            {
                temp[i++] = input[p1] < input[p2] ? input[p1++] : input[p2++];
            }

            while (p1 <= mid)
            {
                temp[i++] = input[p1++];
            }

            while (p2 <= r)
            {
                temp[i++] = input[p2++];
            }

            for (i = 0; i < temp.Count; i++)
            {
                input[l + i] = temp[i];
            }

            Console.WriteLine(CommonHelper.PrintList(input));
        }

        public static bool IsValidBinarySearchTreeByPostOrder(List<int> posrOrder, int length)
        {
            if (posrOrder == null && posrOrder.Count <= 0)
            {
                return false;
            }

            var tempRoot = posrOrder[length - 1];

            int i = 0;
            for (; i < length - 1; i++)
            {
                if (posrOrder[i] > tempRoot)
                {
                    break;
                }
            }

            int j = i;
            for (; j < length - 1; j++)
            {
                if (posrOrder[j] < tempRoot)
                {
                    return false;
                }
            }

            bool validLeft = true;
            bool validRight = true;

            if (i > 0)
            {
                validLeft = IsValidBinarySearchTreeByPostOrder(posrOrder, i - 0);
            }

            if (j > i)
            {
                validRight = IsValidBinarySearchTreeByPostOrder(posrOrder.Skip(i).ToList(), length - i - 1);
            }

            return (validLeft && validRight);
        }

        public static ListNode DuplicateSimpleList(ListNode head)
        {
            if (head == null)
            {
                return null;
            }

            ListNode cloneHead = null;
            ListNode cloneNode = new ListNode(head.Val);
            cloneNode.Next = null;
            cloneHead = cloneNode;

            head = head.Next;

            while (head != null)
            {
                ListNode tempNode = new ListNode(head.Val);
                tempNode.Next = null;

                head = head.Next;
                cloneNode.Next = tempNode;
                cloneNode = cloneNode.Next;
            }

            return cloneHead;
        }

        public static ComplexListNode DuplicateComplexList(ComplexListNode head)
        {
            if (head == null)
            {
                return null;
            }

            Dictionary<ComplexListNode, ComplexListNode> dic = new Dictionary<ComplexListNode, ComplexListNode>();

            ComplexListNode cloneHead = null;
            ComplexListNode cloneNode = new ComplexListNode(head.Val);
            dic.Add(head, cloneNode);
            cloneNode.Next = null;
            cloneHead = cloneNode;

            head = head.Next;

            while (head != null)
            {
                ComplexListNode tempNode = new ComplexListNode(head.Val);
                tempNode.Next = null;

                dic.Add(head, tempNode);

                head = head.Next;
                cloneNode.Next = tempNode;
                cloneNode = cloneNode.Next;
            }

            foreach (var node in dic)
            {
                if (node.Key.Random != null)
                {
                    node.Value.Random = dic[node.Key.Random];
                }
            }

            return cloneHead;
        }

        public static void StringPermutaion(string input, int length)
        {

        }

        public static int BinarySearch(List<int> input, int target)
        {
            int ret = -1;

            if (input == null || input.Count <= 0)
            {
                return ret;
            }

            int l = 0;
            int r = input.Count - 1;

            while (l <= r)
            {
                int mid = (l + r) / 2;

                Console.WriteLine("mid -> " + input[mid] + " target -> " + target);

                if (input[mid] == target)
                {
                    return mid;
                }

                if (input[mid] > target)
                {
                    r = mid - 1;
                }

                if (input[mid] < target)
                {
                    l = mid + 1;
                }
            }

            return ret;
        }

        public static int GetDuplicateNumerCount(List<int> input, int target)
        {
            int firstIndex = -1;
            int lastIndex = -1;

            firstIndex = GetFirstLocation(input, target);

            if (firstIndex >= 0)
            {
                lastIndex = GetLastLocation(input, target);
            }

            return firstIndex < 0 ? firstIndex : lastIndex - firstIndex + 1;
        }

        private static int GetFirstLocation(List<int> input, int target)
        {
            int ret = -1;

            if (input == null || input.Count <= 0)
            {
                return ret;
            }

            int l = 0;
            int r = input.Count - 1;

            while (l <= r)
            {
                int mid = (l + r) / 2;

                Console.WriteLine("mid -> " + input[mid] + " target -> " + target);

                if (input[mid] == target)
                {
                    if ((mid > 0 && input[mid - 1] != target) || mid == 0)
                    {
                        return mid;
                    }
                    else
                    {
                        r = mid - 1;
                    }
                }

                if (input[mid] > target)
                {
                    r = mid - 1;
                }

                if (input[mid] < target)
                {
                    l = mid + 1;
                }
            }

            return ret;
        }

        private static int GetLastLocation(List<int> input, int target)
        {
            int ret = -1;

            if (input == null || input.Count <= 0)
            {
                return ret;
            }

            int l = 0;
            int r = input.Count - 1;

            while (l <= r)
            {
                int mid = (l + r) / 2;

                Console.WriteLine("mid -> " + input[mid] + " target -> " + target);

                if (input[mid] == target)
                {
                    if ((mid < input.Count - 1 && input[mid + 1] != target) || mid == input.Count - 1)
                    {
                        return mid;
                    }
                    else
                    {
                        l = mid + 1;
                    }
                }

                if (input[mid] > target)
                {
                    r = mid - 1;
                }

                if (input[mid] < target)
                {
                    l = mid + 1;
                }
            }

            return ret;
        }
    }
#endregion

#region Helpers
public class CommonHelper
    {
        public static List<int> GenerateList(int count, int upper)
        {
            Random r = new Random();
            List<int> ret = new List<int>();

            for (int i = 0; i < count; i++)
            {
                ret.Add(r.Next(upper));
            }

            return ret;
        }

        public static List<int> GenerateLinearList(int count, int upper)
        {
            Random r = new Random();
            List<int> ret = new List<int>();

            for (int i = 0; i < count; i++)
            {
                ret.Add(r.Next(upper));
            }

            ret.Sort();

            return ret;
        }

        public static string PrintList(List<int> input)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var i in input)
            {
                sb.Append(i + ",");
            }

            return sb.ToString(0, sb.Length - 1);
        }

        public static char ToLower(char c)
        {
            if (c >= 'A' && c <= 'Z')
            {
                return (char)(c - 'A' + 'a');
            }
            else
            {
                return c;
            }
        }

        public static string PrintTreeNode(TreeNode root)
        {
            StringBuilder sb = new StringBuilder();
            Queue<TreeNode> queue = new Queue<TreeNode>();

            if (root == null)
            {
                return sb.ToString();
            }

            queue.Enqueue(root);

            while (queue.Count > 0)
            {
                var temp = queue.Dequeue();

                sb.Append(temp.Val + " ");

                if (temp.Left != null)
                {
                    queue.Enqueue(temp.Left);
                }

                if (temp.Right != null)
                {
                    queue.Enqueue(temp.Right);
                }
            }

            return sb.ToString();
        }

        public static string PrintList(ListNode head)
        {
            StringBuilder sb = new StringBuilder();

            while (head != null)
            {
                sb.Append(head.Val + " -> ");

                head = head.Next;
            }

            var ret = sb.ToString();

            return ret.Substring(0, ret.Length - " -> ".Length);
        }

        public static string PrintComplexList(ComplexListNode head)
        {
            StringBuilder sb = new StringBuilder();

            while (head != null)
            {
                if (head.Random != null)
                {
                    sb.Append(head.Val + " Random " + head.Random.Val + " -> ");
                }
                else
                {
                    sb.Append(head.Val + " -> ");
                }

                head = head.Next;
            }

            var ret = sb.ToString();

            return ret.Substring(0, ret.Length - " -> ".Length);
        }

        public static ListNode GenerateList(int count)
        {
            ListNode head = new ListNode(-1);
            ListNode dummy = head;

            for (int i = 0; i < count; i++)
            {
                ListNode temp = new ListNode(i + 1);
                head.Next = temp;
                head = head.Next;
            }

            return count <= 0 ? null : dummy.Next;
        }

        public static ComplexListNode GenerateComplexList(int count, int ratio)
        {
            Random r1 = new Random();
            Random r2 = new Random();
            Dictionary<int, ComplexListNode> dic = new Dictionary<int, ComplexListNode>();
            ComplexListNode head = new ComplexListNode(-1);
            ComplexListNode dummy = head;

            for (int i = 0; i < count; i++)
            {
                ComplexListNode temp = new ComplexListNode(i + 1);
                dic.Add(i, temp);
                head.Next = temp;
                head = head.Next;
            }

            foreach (var node in dic)
            {
                if (r1.Next(ratio) + 1 == 1)
                {
                    node.Value.Random = dic[r2.Next(dic.Count)];
                }
            }

            return count <= 0 ? null : dummy.Next;
        }
    }
#endregion

#region Models
    public class TreeNode
    {
        public TreeNode(int val)
        {
            this.Val = val;
        }
        public int Val { get; set; }
        public TreeNode Left { get; set; }
        public TreeNode Right { get; set; }
    }

    public class ListNode
    {
        public ListNode(int val)
        {
            this.Val = val;
        }
        public int Val { get; set; }
        public ListNode Next { get; set; }
    }

    public class ComplexListNode
    {
        public ComplexListNode(int val)
        {
            this.Val = val;
        }

        public int Val { get; set; }
        public ComplexListNode Next { get; set; }
        public ComplexListNode Random { get; set; }
    }
#endregion
cainqs(null) - 2019-12-05 0 人
Online questions
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
        double index = 1d;
        while(true)
        {
            Console.WriteLine("index:"+index);
            index ++;
        }
    }
}
payspun(前端大神) - 2019-11-19 0 人
131653
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
payspun(前端大神) - 2019-11-19 0 人
131351563
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
opensmarty(前端大神) - 2019-11-12 0 人
teste
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
alwaysbe(前端大神) - 2019-10-14 0 人
teste
没有了
1/3 下一页