Algorithm
4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
给出一个有n个数字的整形数组,找出里面4个数相加等于目标数字的组。
例如:
输入:数组 nums = [1, 0, -1, 0, -2, 2], 目标数 target = 0.
结果是:
[
[-1, 0, 0, 1],
[-2, -1, 1, 2],
[-2, 0, 0, 2]
]
这题和之前的 3Sum有点类似,相当于确定一个值以后在剩余的数组中计算3sum。
static public IList<IList<int>> FourSum(int[] nums, int target)
{
IList<IList<int>> result = new List<IList<int>>();
if (nums.Length < 4)
{
return result;
}
for (int times = 1; times <= nums.Length - 1; times++)
{
for (int start = 0; start < nums.Length - times; start++)
{
if (nums[start] > nums[start + 1])
{
int cur_num = nums[start];
nums[start] = nums[start + 1];
nums[start + 1] = cur_num;
}
}
}
for (int j = 0; j < nums.Length - 3; j++)
{
if (j > 0 && nums[j] == nums[j - 1])
{
continue;
}
int s_target = target - nums[j];
for (int i = j+1; i < nums.Length - 2; i++)
{
if (i > j + 1 && nums[i] == nums[i - 1]) continue;
int left = i + 1, right = nums.Length - 1;
while (left < right)
{
if (nums[i] + nums[left] + nums[right] == s_target)
{
result.Add(new List<int>() { nums[j], nums[i], nums[left], nums[right] });
left++;
right--;
while (left < right && nums[left] == nums[left - 1])
{
left++;
}
while (left < right && nums[right] == nums[right + 1])
{
right--;
}
}
else if (nums[i] + nums[left] + nums[right] > s_target)
{
right--;
}
else
{
left++;
}
}
}
}
return result;
}
Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.
Example:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
给定一个链表和n值,需要移除链表中,从链表的最后端开始地n个值。
基本思路,通过对链表的一次完整遍历,找到链表中从末端开始第n个点上一个节点。
public class ListNode
{
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
static public ListNode RemoveNthFromEnd(ListNode head, int n)
{
ListNode cur_node = head;
int index = 0;
ListNode find_node_f = null;
while (cur_node!= null)
{
index++;
if ((index - n)>0)
{
if ((index - n) == 1)
{
find_node_f = head;
}
else
{
find_node_f = find_node_f.next;
}
}
cur_node = cur_node.next;
}
if (index >= n)
{
if (find_node_f == null)
{
head = head.next;
}
else
{
find_node_f.next = find_node_f.next.next;
}
}
else
{
return null;
}
return head;
}
遍历过程如图所示:
Review
- Selenium+C#自动化脚本开发学习
https://www.cnblogs.com/Gougougogogo/p/5755118.html
https://www.cnblogs.com/vaevvaev/p/7041858.html 感觉像是文章的出处
这两篇文章只能做为入门参考,很多接口还是要在代码中尝试使用。 - 破解滑块验证 - 使用selenium模拟登录京东,基于C#的实现
https://blog.csdn.net/zxhcm521/article/details/84641965
这个很有意思可以详细研究下
Tips&Share
- 最近在尝试用 selenium 做一个工作上的小工具,使用的编程语言是 c#。在启动的时候会报错:Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (SessionNotCreated)。看错误信息,问题出在IE的安全级别。修改IE安全中的保护模式,就可以解决这个问题,修改方法(win7):在“控制面板”->“网络和Internet”->“管理浏览器加载项”->“安全”->“受限制站点” 把启用保护模式的勾去掉。
- Selenium 执行js代码的函数是:((IJavaScriptExecutor)m_driver).ExecuteScript(“js代码”);
看其他python下使用 selenium 的例子,python 中的这个函数可以用js文件名作为参数,在 c# 中ExecuteScript函数的参数只能是字符串,也就是js代码。我的解决方法是把js代码写在文件中,读取文件中的内容然后再通过 ExecuteScript 执行 js 代码。 - selenium c# Actions 类在哪里
参考网站:https://blog.csdn.net/hanqionglaaa/article/details/8995262
可以看到:org.openqa.selenium.interactions.Actions
using OpenQA.Selenium.Interactions; - [C#] 字符串的分割与截取(split or substring)
https://blog.csdn.net/ftell/article/details/81739215
字符串分割:
string data = "THExxQUICKxxBROWNxxFOX";
string[] xx = data.Split(new string[] { "xx" }, StringSplitOptions.None);
foreach (string item in xx)
System.Console.Write(item + " ");
- windowsform 禁止调整窗口大小
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 在form的属性中也能找到 FormBorderStyle 属性进行设置。 - win10 关闭U盘自动打开,在左下角输入框搜索“自动播放”,把自动播放关掉就可以了,也可以单独设置“可移动驱动器”为“不执行操作”
- 最近停了一周,后续会增加刷题量,要不然这一周的任务有点太糊拢。